Regex for "search query" string

Discussion in 'Perl Misc' started by nick.p.doyle@gmail.com, Feb 22, 2005.

  1. Guest

    (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
    , Feb 22, 2005
    #1
    1. Advertising

  2. phaylon Guest

    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.
    phaylon, Feb 22, 2005
    #2
    1. Advertising

  3. Guest

    " 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.
    , Feb 22, 2005
    #3
  4. Guest

    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?
    , Feb 22, 2005
    #4
  5. 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
    A. Sinan Unur, Feb 22, 2005
    #5
  6. <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 22, 2005
    #6
  7. <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 22, 2005
    #7
  8. Guest

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

    Cheers Tad.
    , Feb 23, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mladen Adamovic
    Replies:
    0
    Views:
    731
    Mladen Adamovic
    Dec 4, 2003
  2. Mladen Adamovic
    Replies:
    3
    Views:
    14,588
    Mladen Adamovic
    Dec 5, 2003
  3. Xah Lee
    Replies:
    1
    Views:
    938
    Ilias Lazaridis
    Sep 22, 2006
  4. Replies:
    3
    Views:
    746
    Reedick, Andrew
    Jul 1, 2008
  5. Ruby Newbee

    regex =~ string or string =~ regex?

    Ruby Newbee, Jan 4, 2010, in forum: Ruby
    Replies:
    3
    Views:
    131
    Kirk Haines
    Jan 4, 2010
Loading...

Share This Page