Regex question

J

John

I am having a lot of trouble creaing the following regex :

Match a quoted string unless it is preceded by '--', the '--' can only
be preceded by whitespace.

e.g for a target string of :

DISPLAY-HINT "1x:"

"1x:" should be matched

for a target string of :

-- DISPLAY-HINT "1x:"

nothing should be matched.



Any help would be much appreciated.

John.
 
G

Gunnar Hjalmarsson

John said:
Match a quoted string unless it is preceded by '--', the '--' can only
be preceded by whitespace.

e.g for a target string of :

DISPLAY-HINT "1x:"

"1x:" should be matched

for a target string of :

-- DISPLAY-HINT "1x:"

nothing should be matched.

/".+"/ and !/^ *--/
 
A

axel

John said:
I am having a lot of trouble creaing the following regex :

Match a quoted string unless it is preceded by '--', the '--' can only
be preceded by whitespace.

e.g for a target string of :

DISPLAY-HINT "1x:"

"1x:" should be matched

for a target string of :

-- DISPLAY-HINT "1x:"

nothing should be matched.

Do I understand this correctly... when you say "1x" should be matched,
do you want to capture this value? If then the following will ignore
white-space at the start of the string, not match '--' at the start of
the string:

/^\s*[^ -]{2}.*"(.*)"/

The captured valuer will be in $1.

Axel
 
G

Gunnar Hjalmarsson

John said:
Match a quoted string unless it is preceded by '--', the '--' can only
be preceded by whitespace.

e.g for a target string of :

DISPLAY-HINT "1x:"

"1x:" should be matched

for a target string of :

-- DISPLAY-HINT "1x:"

nothing should be matched.

Do I understand this correctly... when you say "1x" should be matched,
do you want to capture this value? If then the following will ignore
white-space at the start of the string, not match '--' at the start of
the string:

/^\s*[^ -]{2}.*"(.*)"/

What about 'P-HINT "1x:"' or 'A HINT "1x:"'? ;-)
 
A

axel

Gunnar Hjalmarsson said:
John said:
Match a quoted string unless it is preceded by '--', the '--' can only
be preceded by whitespace.

e.g for a target string of :

DISPLAY-HINT "1x:"

"1x:" should be matched

for a target string of :

-- DISPLAY-HINT "1x:"

nothing should be matched.

Do I understand this correctly... when you say "1x" should be matched,
do you want to capture this value? If then the following will ignore
white-space at the start of the string, not match '--' at the start of
the string:

/^\s*[^ -]{2}.*"(.*)"/

What about 'P-HINT "1x:"' or 'A HINT "1x:"'? ;-)

It wouldn't works :(

So, maybe;

/^ (?! \s*--) .* "(.*)" /x

Axel
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,462
Latest member
ChanaLipsc

Latest Threads

Top