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!

Pattern matching exclusion 2

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
US
Ok, this SHOULD be easy, but for some reason I'm having a hard time with it. I want to match on '"' (double quote) but not when it's preceded by a backslash ('\"').

I tried this:
Code:
$string =~ /[^\\]\"/
but, it doesn't work. I've also tried all sorts of variations on this...but, can't get it to work!?!?! Any ideas are greatly appreciated!
 
FYI: What I'm actually trying to do is to count the number of double quotes in a string...excluding those double quotes that have a backslash preceding it. I was just trying to simplify matters with my example...and they kind of changed the problem. Here is what I'm REALLY trying to do:

Code:
$count =~ tr/[^\\]\"//;
 
You want a "negated look-behind asserttion": (?<!regexp)

Code:
$var  = 'test\" test "test" test \"test\" test "test" ';
$c++ while $var =~ m/(?<!\\)"/g;
print $c;


tr/// has no concept of character classes or patterns so it can't be used in this case.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
That is a new concept to me!! Thanks...it's been awhile since I've been able to learn a new perl concept!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top