Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > newbie's regex question

Reply
Thread Tools

newbie's regex question

 
 
NPtr
Guest
Posts: n/a
 
      02-10-2007
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.


 
Reply With Quote
 
 
 
 
hiwa
Guest
Posts: n/a
 
      02-10-2007
On Feb 11, 7:55 am, "NPtr" <(E-Mail Removed)-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.

 
Reply With Quote
 
 
 
 
NPtr
Guest
Posts: n/a
 
      02-11-2007

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


 
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
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
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
Java regex imposture re: Perl regex compatibility a_c_Attlee@yahoo.com Java 2 05-06-2005 12:16 AM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments