Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regex for "search query" string

Reply
Thread Tools

Regex for "search query" string

 
 
nick.p.doyle@gmail.com
Guest
Posts: n/a
 
      02-22-2005
(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

 
Reply With Quote
 
 
 
 
phaylon
Guest
Posts: n/a
 
      02-22-2005
nick.p.doyle wrote:

> (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.

--
http://www.dunkelheit.at/
sapere aude.

 
Reply With Quote
 
 
 
 
nick.p.doyle@gmail.com
Guest
Posts: n/a
 
      02-22-2005
" 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.

 
Reply With Quote
 
nick.p.doyle@gmail.com
Guest
Posts: n/a
 
      02-22-2005
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?

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      02-22-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1109099431.912428.296900
@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.

> mm?


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

Sinan
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      02-22-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:
> " 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.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      02-22-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:
> 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!


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
nick.p.doyle@gmail.com
Guest
Posts: n/a
 
      02-23-2005
>Matches go left to right in Perl, so put the thing you want
to match first leftmost.

Cheers Tad.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regex =~ string or string =~ regex? Ruby Newbee Ruby 3 01-04-2010 06:04 PM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
String Pattern Matching: regex and Python regex documentation Xah Lee Java 1 09-22-2006 07:11 PM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments