Using regular expressions to copy substrings into an array?

Discussion in 'Perl Misc' started by Amittai Aviram, Nov 15, 2004.

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

    http://www.amittai.com
    Amittai Aviram, Nov 15, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Douglas
    Replies:
    0
    Views:
    582
    Jay Douglas
    Aug 15, 2003
  2. Timothy Hume
    Replies:
    2
    Views:
    478
    Brian Szmyd
    Sep 10, 2004
  3. Robert Dodier
    Replies:
    4
    Views:
    320
    Raymond Hettinger
    Mar 14, 2006
  4. candide
    Replies:
    18
    Views:
    1,268
    Gregor Lingl
    Aug 18, 2009
  5. Noman Shapiro
    Replies:
    0
    Views:
    216
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page