Using regular expressions to copy substrings into an array?

A

Amittai Aviram

Hi! I need to take the contents of a text file, find certain patterns of
text within the file, and, wherever those patterns occur, push those
instances of the pattern onto an array. The pattern includes a tagged term
and the two words before it and after it:

firstword secondword <tag>term</tag> fourthword fifthword

It may well be that the peripheral words of one phrase overlap with those of
a neighboring phrase, but I need to copy each instance as a separate item in
the array.

I need to recognize instances of the pattern across newlines, so I am
reading the contents of the file line by line and concatenating the lines
onto a single string. Then I could use the /s modifier if appropriate --
but I don't know exactly how to use matching for my purpose.

Any suggestions as to how to go about this? Thanks.

Amittai Aviram
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top