CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
pair of quotes with no escaped quotes in it?

 



mike_robb
Novice

Feb 16, 2001, 7:11 PM

Post #1 of 2 (1196 views)
pair of quotes with no escaped quotes in it? Can't Post

[^\\]'([^']*)[^\\]'"

I'm looking for reg exp that will match any string inside a pair of single quotes where the outside single quotes are not backslashed \' and there can be baskslashed single quotes inside the matched pattern:

valid -> 'stuff \' stuff'
not valid -> \'stuff stuff'
not valid -> 'stuff stuff\'
not valid -> 'stuff ' stuff'

and if that is too easy for someone - can this pattern be bounded on one line (no \n in the pattern)?

TIA!





japhy
Enthusiast / Moderator

Feb 20, 2001, 7:16 AM

Post #2 of 2 (1188 views)
Re: pair of quotes with no escaped quotes in it? [In reply to] Can't Post

Ok, I suggest this approach:


Code
$string = q{This is \'not\' it yet... 'this \'is\' it!'}; 

($quoted) = $string =~ m{
^

# advance past all the non-wanted stuff
[^'\\]* (?: \\. [^'\\]* ) *

# match and save what we want
' ( [^'\\]* (?: \\. [^'\\]* ) * ) '
}x;

For an explanation of that regex, enter it into the OGRE.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives