finding <

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
michelvh
Forum Newbie
Posts: 2
Joined: Wed Jan 07, 2009 1:08 pm

finding <

Post by michelvh »

I have to find "five < six"
in the next line:

five < six<Tr>

Can someone give a regexp for this?

Can't find the solution.

Michel
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: finding <

Post by prometheuzz »

michelvh wrote:I have to find "five < six"
in the next line:

five < six<Tr>

Can someone give a regexp for this?

Can't find the solution.

Michel
The regex for that is:

Code: Select all

'/five < six/'
If that was not the answer you were hoping for, I suggest you provide some additional information. Because beside that single example, you did not explain anything about your input.

Good luck.
michelvh
Forum Newbie
Posts: 2
Joined: Wed Jan 07, 2009 1:08 pm

Re: finding <

Post by michelvh »

That's not what I am looking for, "five < six"
is just an example.

What I have to find is
from the beginning of the string all
characters until a < is followed by a T. (not a space)

Michel
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: finding <

Post by andyhoneycutt »

Code: Select all

'/(.+)<T/'
-Andy
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: finding <

Post by prometheuzz »

michelvh wrote:That's not what I am looking for, "five < six"
is just an example.
...
Yes, I figured that much. My point was that you gave a very unclear explanation of your problem with just a single example and without a proper explanation of your requirement. Wouldn't you agree?
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: finding <

Post by prometheuzz »

andyhoneycutt wrote:

Code: Select all

'/(.+)<T/'
-Andy
That won't work for:

Code: Select all

five < six<Tr seven > six <Tr>
and

Code: Select all

five < six \n seven > six <Tr
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: finding <

Post by andyhoneycutt »

True, it won't work for the above examples. It almost matches for the criteria specified, with the exception that I didn't match for white space. This may be a more precise pattern:

Code: Select all

'/([\w\s]+<[\w\s]+)+<T/'
This matches:

Code: Select all

'a < b <T'
"a \n<b <\n c...<T"
'a < b < c ... <T'
-Andy
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: finding <

Post by GeertDD »

What I have to find is
from the beginning of the string all
characters until a < is followed by a T. (not a space)

Code: Select all

^.*?(?=<T)
Post Reply