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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opposite of ¦ in regex?

Status
Not open for further replies.

danielhozac

Programmer
Aug 21, 2001
2,058
SE
What is the opposite of | in parantheses in a regular expression? Is there even an opposite?

//Daniel
 
An opposite? When talking about opposites, one is normally refering to the negation of a character class...

\w means all word characters a-zA-Z0-9_
\W is the opposite

[2-5] digits 2,3,4 & 5
[^2-5] the opposite of that character class

So to answer the question what's the opposite of (\|) in a regex, the answer would likely be ([^\|]).

But you're not talking about that are you. Your asking what's the opposite of (dog|cat). Here we are saying "dog" or "cat" If you want to say dog and cat you could use two regex's like this... just to be easy:

if($string =~ m/dog/ && $string =~ m/cat/){ do this... }

Is this what you meant? Hope it was!

--Jim
 
Yeah, that was what I meant, but I was wondering if there was a character that automatically did it... I guess I will use the technique mentioned above. Thanks.

//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top