in reply to String Substitution Operator
From what I can tell, it looks to me like in the first regexp, you're only capturing with one set of parens. That means that $1 is the only variable that will have anything captured into it, in your first regexp. Nothing is populating $2 and $3. Also, $1 will only have something captured into it if the overall match was a success. Also, there is no need to use square brackets around \W if you're only matching one character, with a built-in character class. The square brackets are generally used to create custom character classes.
I hope this is of some help.
If your book gave you the regexp you have shown us, it would be a good candidate for the garbage heap. You might really get a lot out of perlretut, followed by perlfaq6, followed by perlre. Those three online POD's give a very thorough explanation of regular expressions, and start out (in perlretut) at a pace that isn't too overwhelming.
As far as what $1 $2 and $3 would "obviously" contain, I have no idea because you didn't provide the actual input string for us to see.
Your second regexp (the one that follows "THIS should work:" will substitute the first non-word character in the string with a hyphen. Is that what you meant by "work"? I might be missing something too. ;)
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: String Substitution Operator
by hehenoobhehe (Novice) on Oct 23, 2003 at 08:42 UTC | |
by hehenoobhehe (Novice) on Oct 23, 2003 at 08:47 UTC | |
by Roger (Parson) on Oct 23, 2003 at 09:01 UTC | |
by Aragorn (Curate) on Oct 23, 2003 at 09:05 UTC |