in reply to Re: Regexp problem
in thread Regexp problem

chromatic wrote that the OP's regex matches:
> the literal string "frame=" > followed by a character class containing alphanumerics and the under +score > repeated zero or more times > ...
I don't think this is right, particularly the bit about the character class. Within a character class definition ("[]"), an asterick matches an asterick--it doesn't have a meta-meaning within a character class. So what that character class actually matches is alphanumerics, the underscore, and an asterick. And it matches it *one time*-- not zero, not more than 1.

That's why just the "c" from "content" got included-- because the character class swipes up one character.

As an example, take a look at this:

my $print_link = "http://www.foo.com/bar?method=go&frame=*content&name +=baz"; $print_link =~ s/frame=[\w*]&*//; print $print_link, "\n";
This prints out
http://www.foo.com/bar?method=go&content&name=baz
So the regex matched "frame=*".

Replies are listed 'Best First'.
RE: RE: Re: Regexp problem
by chromatic (Archbishop) on Apr 18, 2000 at 22:33 UTC
    Whoops, you're right. Moral of the story, never leave a writeup half finished and come back thirty minutes later without reviewing things.

    I must have confused the character class braces with the grouping brackets, as the original poster did. Moral of THAT story, always ask yourself if you want curved brackets or square braces.

RE: RE: Re: Regexp problem
by Maclir (Curate) on Apr 19, 2000 at 01:39 UTC
    Thank you. I made two mistakes, using square brackets when I should have use parenthesis, and thinking that a * within the square brackets would have the same effect as using a * outside the square brackets, in the normal part of the regexp.
    Needless to say, it now works as I originally intended. Maybe I need to read further into the details of regexps, and to determine when one should use square brackets or (). I was under the impression that you only grouped things with () if you wished to later refer to them as a substitution string (like $1).
    Thanks.