Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Thank you for a reply. I'm sorry to say I think I am still a bit too inexperienced in the Perl language to follow the code in your reply fully but I have had a go and tried to answer your questions as fully as I can;

What is my RegExp trying to match? I am trying to match and substitute the words in the string $_ by asking the user to input the correct string of number values. Originally I tried to match and substitute in each 'if' decision after the user input, however doing it this way I could not see a way to match to any string other than the first available without using a string literal.

i.e. $_ = "three, four" I could not see a way to match to 'four' without using the literal, whereas, as I understood it the power of a RegExp came from it being able to find something in a string without a literal constant.

In essence I suppose what I am trying to do is: Psuedo-

1st substitute/([A-Z][a-z][\W][\b])/<userinput>/;
then 2nd substitute/(NOT THIS ONE[A-Z][a-z][\W][\b])(THIS ONE[A-Z][a-z][\W] +[\b])/<userinput>/;
then 3rd substitute/(NOT THIS ONE[A-Z][a-z][\W][\b])(AND NOT THIS ONE[A-Z][ +a-z][\W][\b])(BUT THIS ONE[A-Z][a-z][\W][\b])/<userinput>/;

Does that make any kind of sense?

Your first RegEx(A-Za-z.\b) matches nothing because no words in the string are 2-characters in size, adding a plus to the lower case set a-z+ would match the first word, but as I understand it . is capable of matching nothing as well as anything, therefore I beleive it would match nothing and the next character in the match would be a comma when the match is actually looking for a break.

Why does the second regex match something, but only once when you want it to match several times? I'm unsure about this part so I can't answer this question easily, (?: , | \b)). ? allows the preceeding character to be optional (but there is no preceeding character?) and I can't see the use of a colon in this context. I understand however that the comma is a literal constant to look for, OR a break. '/x' I have not yet come across. Has it only matched once because it is not part of a loop to tell it to match as many times as I want? I don't want the comma, so perhaps look only for A-Za-z but then how then do I ignore these the second time I want to match? If I must match only once (as I originally had tried to do, then why does Perl not find anything for $2 $3 and $4?

As for Update 1 & 2 I'm afraid they're far beyond my capablities at this moment in time, I realise they're more than likely a cleaner way to write the code, I was simply trying to write a program for myself to show I understood RegExp (but clearly that is not the case!), I'm afraid the code in the two updates are far too advanced for me at this moment ;/


In reply to Re^2: RegExp substitution by Keystone
in thread RegExp substitution by Keystone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-16 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found