Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to match multichar atoms in regexp?

Status
Not open for further replies.

expostfacto

Programmer
Sep 10, 2001
31
US
if ('bbbbbasasdf' =~ /([^(asdf)]*)/) {
print $1;
}

above prints bbbbb when bbbbbas is desired. Is there any way to do this with regexp? I really really really don't want to have to learn parse::recdescent. :)
 
/([^(asdf)]*)/

The square brackets means character class - each character in between the square brackets is a member of a character class that you are defining.

When you say [^(asdf)] you are really saying match any character which is not(^) one of the characters "(", "a", "s",
"d", "f", or ")".

This took some research - I looked in "Programming Perl" - 3rd edition p. 166 to get a definition of the "caret" - 3rd paragraph down.

Why not use something like this:

if ('bbbbbasasdf' =~ /(\w+)asdf/) {
print "$1\n";
}

HTH. Hardy Merrill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top