Recursively Removing Embedded Quotes

B

Buck

I have a routine that recursively removes embedded parentheses and it
works just fine. But when I adapt that regex to do the same thing
with single quotes, it doesn't work. It matches two quoted strings,
not the inner one.

E.g. the regex below

'[^'']*'

should match inner, but it matches left and right.

what am I doing wrong?

' left ' inner ' right '
 
M

Mirco Wahab

Buck said:
I have a routine that recursively removes embedded parentheses and it
works just fine.

I didn't find one in your posting.
But when I adapt that regex to do the same thing
with single quotes, it doesn't work. It matches
two quoted strings, not the inner one.
E.g. the regex below
'[^'']*'
should match inner, but it matches left and right.
what am I doing wrong?
' left ' inner ' right '

The regex causes the engine to 'eat up' the
quotes around inner, to extract all quoted
phrases, you could use zero-with assertions:

...
my $text = q{ ' left ' inner ' right ' };

my @matches = $text =~ /(?<=')[^']+(?=')/g;
...

Regards

Mirco
 
B

Brian McCauley

I have a routine that recursively removes embedded parentheses and it
works just fine. But when I adapt that regex to do the same thing
with single quotes, it doesn't work. It matches two quoted strings,
not the inner one.

E.g. the regex below

'[^'']*'

should match inner, but it matches left and right.

' left ' inner ' right '
what am I doing wrong?

Expecting you computer to be psychic.

What is it about the sample data that indicates that it is a nested
string and not two separate strings?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top