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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Feb 16, 2001, 7:11 PM

Post #1 of 2 (3284 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)?


Enthusiast / Moderator

Feb 20, 2001, 7:16 AM

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

Ok, I suggest this approach:

$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
' ( [^'\\]* (?: \\. [^'\\]* ) * ) '

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