hoppfrosch has asked for the wisdom of the Perl Monks concerning the following question:
Further investigation shows, that [.] is not a valid character class ...my $html="<table>\nt1\n<\/table>\n<table>\nt2\n<\/table>\n" $html =~ m/<table>(.*?)</table>/; # Failed, since 'The period '.' matches any character but ``\n'' $html =~ m/<table>(.*?)</table>/s; # SUCCESS, since 's modifier (//s): Treat string as a single long # line. '.' matches any character, even "\n"' $html =~ m/<table>[a-zA-Z0-9 \r\n<>"!-=]*?</table> # SUCCESS - Emulating '.' with defining a own character class, # containing 'any' characters (or a subset in this example) including # '\n' # NO s modifier (//s) needed $html =~ m/<table>[.\n]*?</table>; # Same as above, but using '.' instead of explicitly listing all # characters ... # Failed, WHY? Why is '.' not allowed within a character class?
Edit by castaway - use html entities instead of angled brackets
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RegEx: Why is [.] not a valid character class?
by bart (Canon) on Nov 17, 2004 at 14:57 UTC | |
|
Re: RegEx: Why is [.] not a valid character class?
by larryp (Deacon) on Nov 17, 2004 at 17:33 UTC | |
|
Re: RegEx: Why is [.] not a valid character class?
by marcelo.magallon (Acolyte) on Nov 17, 2004 at 21:31 UTC | |
|
Re: RegEx: Why is [.] not a valid character class?
by ikegami (Patriarch) on Nov 17, 2004 at 16:17 UTC | |
by ihb (Deacon) on Nov 18, 2004 at 02:49 UTC |