Regex for "search query" string

N

nick.p.doyle

(I'm actually writing this in vb.net but the .net group gave no
response to my regex q's)
Given a "typical string for a search" containing quoted phrases and
logical operators
e.g. betty AND "the jets"
I want to match first "the jets" then the " and ", then anything else.

My current regex for "a or b" is "( or )|(.+)", because I thought the
alternation operator would operate in an ordered fashion but apparently
not.

Advice most welcome, thanks.
Nick
 
P

phaylon

nick.p.doyle said:
(I'm actually writing this in vb.net but the .net group gave no response
to my regex q's)

I have about 40_000 in my list of groups, how much of them are you going
to try out?
Given a "typical string for a search" containing quoted phrases and
logical operators
e.g. betty AND "the jets"
I want to match first "the jets" then the " and ", then anything else.

At first, the term " and " is very confusing and I (not a native speaker)
needed some time to get it. What means "first"? first position? what means
you want to match "anything else"?
My current regex for "a or b" is "( or )|(.+)", because I thought the
alternation operator would operate in an ordered fashion but apparently
not.

I wouldn't do this with regular expressions.
 
N

nick.p.doyle

" and " means a space, then the letters 'a', 'n' and 'd', then another
space
Like in "homer and bart" but not "flanders".

"first" as in the order in which things are matched

"anything else" is things not covered by the other case - letter,
numbers, whatever - a period in regex language.
 
N

nick.p.doyle

In code it would be something like :
$query = "betty and \"the jets\";
while /super regex here/
print $1;

To be displaying :
"the jets"
" and "
betty

mm?
 
A

A. Sinan Unur

(e-mail address removed) wrote in @z14g2000cwz.googlegroups.com:

Please quote some context when you are replying.
In code it would be something like :
$query = "betty and \"the jets\";
while /super regex here/
print $1;

That does not compile.
To be displaying :
"the jets"
" and "
betty

WHat you have here is a pseudo-specification for a mini language. If I were
you, I would be looking at modules with 'Parser' in their names.

No thanks. Do you have any mini Mars bars though?

Sinan
 
T

Tad McClellan

" and " means a space, then the letters 'a', 'n' and 'd', then another
space
Like in "homer and bart" but not "flanders".


This regex will match that:

/ and /

"first" as in the order in which things are matched


Matches go left to right in Perl, so put the thing you want
to match first leftmost.
 
T

Tad McClellan

In code it would be something like :
$query = "betty and \"the jets\";
while /super regex here/
print $1;


If you post Perl code, we will help you fix it.

If not, then you are on your own.

Good luck!
 
N

nick.p.doyle

Matches go left to right in Perl, so put the thing you want
to match first leftmost.

Cheers Tad.
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top