Query regarding RegEx

Discussion in 'Java' started by emo, Apr 27, 2008.

  1. emo

    emo Guest

    I am not good in regular expressions. I am struck with one issue,
    please help.

    I need to match the following texts

    NOT 'any text' = 'any text'

    the alternate text for 'any text' can be "any text" or any integer or
    float value.

    Patterns that should NOT match.

    NOT ('value' = 'value')

    the difference between the above two are parenthesis.

    Thanks in advance,
    -EM-
     
    emo, Apr 27, 2008
    #1
    1. Advertising

  2. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    emo schreef:
    | I am not good in regular expressions. I am struck with one issue,
    | please help.
    |
    | I need to match the following texts
    |
    | NOT 'any text' = 'any text'
    |
    | the alternate text for 'any text' can be "any text" or any integer or
    | float value.
    |
    | Patterns that should NOT match.
    |
    | NOT ('value' = 'value')
    |
    | the difference between the above two are parenthesis.

    Try this one, but without more clarification, it is bound to fail on
    some input:

    "NOT ['\"](.[^'\"])['\"] = ['\"](.[^'\"])['\"]"

    escaped for Java. Use Matcher.find() and Matcher.group(1),
    Matcher.group(2) to find both values.

    An integer or float value in a string is still just characters, so no
    need to treat them special. You’ll have to find out what they are to
    use them, though.

    H.
    - --
    Hendrik Maryns
    http://tcl.sfs.uni-tuebingen.de/~hendrik/
    ==================
    http://aouw.org
    Ask smart questions, get good answers:
    http://www.catb.org/~esr/faqs/smart-questions.html
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.4-svn0 (GNU/Linux)
    Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

    iD4DBQFIFZnve+7xMGD3itQRAvakAJ0abbQFis90VKWj9vPyAdzUgjvD7ACYpOYn
    u+7AtVfZ/MaHmNyfQ99uPQ==
    =yuVc
    -----END PGP SIGNATURE-----
     
    Hendrik Maryns, Apr 28, 2008
    #2
    1. Advertising

  3. emo

    Roedy Green Guest

    On Sun, 27 Apr 2008 11:55:38 -0700 (PDT), emo <>
    wrote, quoted or indirectly quoted someone who said :

    >NOT 'any text' = 'any text'
    >
    >the alternate text for 'any text' can be "any text" or any integer or
    >float value.
    >
    >Patterns that should NOT match.
    >
    >NOT ('value' = 'value')


    More concrete examples would help. I suspect though that you will not
    able to do this with pure regex. It cannot detect a repeated string.
    You would have to detect that outside the regex. When you get into
    that sort of complexity, normally you go up a notch to a parser.

    See http://mindprod.com/jgloss/parser.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Apr 28, 2008
    #3
  4. emo

    Daniel Pitts Guest

    Roedy Green wrote:
    > On Sun, 27 Apr 2008 11:55:38 -0700 (PDT), emo <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    >> NOT 'any text' = 'any text'
    >>
    >> the alternate text for 'any text' can be "any text" or any integer or
    >> float value.
    >>
    >> Patterns that should NOT match.
    >>
    >> NOT ('value' = 'value')

    >
    > More concrete examples would help. I suspect though that you will not
    > able to do this with pure regex. It cannot detect a repeated string.
    > You would have to detect that outside the regex. When you get into
    > that sort of complexity, normally you go up a notch to a parser.
    >
    > See http://mindprod.com/jgloss/parser.html


    You *can* do that in regex:

    public class Matches {
    public static void main(String[] args) {
    String pattern = "NOT ([^(].*) = \\1";
    String yes = "NOT 'any text' = 'any text'";
    String no = "NOT ('value' = 'value')";
    System.out.println("\"" + yes + "\".matches(pattern) = "
    + yes.matches(pattern));
    System.out.println("\"" + no + "\".matches(pattern) = "
    + no.matches(pattern));

    }
    }



    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
     
    Daniel Pitts, Apr 29, 2008
    #4
  5. emo

    Roedy Green Guest

    On Mon, 28 Apr 2008 17:20:57 -0700, Daniel Pitts
    <> wrote, quoted or indirectly
    quoted someone who said :

    >You *can* do that in regex:


    I am not at all clear what "this" is from his examples.

    I have learned something new. I thought \1 was only for replacing.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Apr 29, 2008
    #5
    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. Bakkurudeen Ali J

    Query Regarding 2D wavelet transformation

    Bakkurudeen Ali J, Sep 14, 2004, in forum: VHDL
    Replies:
    0
    Views:
    569
    Bakkurudeen Ali J
    Sep 14, 2004
  2. Kingfischer

    Query regarding VHDL "if" statement

    Kingfischer, Oct 15, 2004, in forum: VHDL
    Replies:
    2
    Views:
    2,412
    rickman
    Oct 15, 2004
  3. balaji

    query regarding web service

    balaji, Feb 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    331
    Rajiv R
    Feb 18, 2004
  4. Prabhu Gurumurthy

    Question regarding lists and regex

    Prabhu Gurumurthy, Nov 9, 2006, in forum: Python
    Replies:
    2
    Views:
    236
  5. Replies:
    3
    Views:
    773
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page