newbie's regex question

N

NPtr

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

hiwa

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

NPtr

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.
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top