Matching neighbouring words of a pattern using Regex
From: CV (cv_at_nospamadelphia.net)
Date: 08/30/04
- Next message: Joe Smith: "Re: reg exp"
- Previous message: Gunnar Hjalmarsson: "Re: reg exp"
- Next in thread: Gunnar Hjalmarsson: "Re: Matching neighbouring words of a pattern using Regex"
- Reply: Gunnar Hjalmarsson: "Re: Matching neighbouring words of a pattern using Regex"
- Reply: Charles DeRykus: "Re: Matching neighbouring words of a pattern using Regex"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 30 Aug 2004 15:45:58 -0400
How can I match 'n' number of neighbouring words of a pattern using regular
expressions?
For example, suppose I am looking for the pattern "length xyz cm" in some
text. where xyz is a number - integer or fraction or decimal point. How can
I also grab about 3-5 words on either side of the pattern "length xyz cm"?
The surrounding words are not always constant & may be variable. Also, the
original text to be matched is not just a single sentence, but lines from a
file concatenated together - so the text has many newline characters too. I
only want the words on the same line as the pattern.
I have tried using regex of the form
/\b(\w*)\b(\w*)\b(\w*)\b($pattern)\b(\w*)\b(\w*)\b(\w*), but this doesn't
work for some reason. Could someone please offer some suggestions?
thanks!
- Next message: Joe Smith: "Re: reg exp"
- Previous message: Gunnar Hjalmarsson: "Re: reg exp"
- Next in thread: Gunnar Hjalmarsson: "Re: Matching neighbouring words of a pattern using Regex"
- Reply: Gunnar Hjalmarsson: "Re: Matching neighbouring words of a pattern using Regex"
- Reply: Charles DeRykus: "Re: Matching neighbouring words of a pattern using Regex"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|