newbie's regex question

Discussion in 'Java' started by NPtr, Feb 10, 2007.

  1. NPtr

    NPtr Guest

    I need to crop all text between one expression(let it be expr1) and the
    first match of another(expr2). The text looks like:
    some text expr1 some text expr2 some text expr2. I know nothing
    about length of the text.
    The point is that i can't just write expr1(.*)expr2, because the expr2 is
    repeated more than one time (and it crops everything before the last match
    of expr2 ), but I need the text just before the first match of expr2. Maybe
    I can say that "some text" must not contain expr2, but i don't know how to
    do this. Help me please.

    Thank you in advance.
    NPtr, Feb 10, 2007
    #1
    1. Advertising

  2. NPtr

    hiwa Guest

    On Feb 11, 7:55 am, "NPtr" <-kpi.kiev.ua.del.it>
    wrote:
    > I need to crop all text between one expression(let it be expr1) and the
    > first match of another(expr2). The text looks like:
    > some text expr1 some text expr2 some text expr2. I know nothing
    > about length of the text.
    > The point is that i can't just write expr1(.*)expr2, because the expr2 is
    > repeated more than one time (and it crops everything before the last match
    > of expr2 ), but I need the text just before the first match of expr2. Maybe
    > I can say that "some text" must not contain expr2, but i don't know how to
    > do this. Help me please.
    >
    > Thank you in advance.


    Use reluctant quantifiers.
    See API doc for Pattern class.
    hiwa, Feb 10, 2007
    #2
    1. Advertising

  3. NPtr

    NPtr Guest


    > Use reluctant quantifiers.
    > See API doc for Pattern class.

    Thanks, it works. Sorry for the stupid question.
    I thought I had tried these qualifiers, but in fact I hadn't.
    NPtr, Feb 11, 2007
    #3
    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. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    698
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,622
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    596
  4. Xah Lee
    Replies:
    1
    Views:
    939
    Ilias Lazaridis
    Sep 22, 2006
  5. Replies:
    3
    Views:
    754
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page