C
CV
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!
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!