Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hello, I am a beginner trying to use a regular expression to search for a pattern. The problem is that the pattern is split across multiple lines. For example, if I am searching for 'abc' in a file containing the following: abcdefab cdefa bcdef I should get 3 matches. The first thing I tried was to write a While script that reads the file line by line, chomps the line and stores everything in a single variable which I then search. This works well when I use a small sample file but for some reason doesnt work with my actual txt file which is several hundred mb so maybe it is not the most efficient way of doing this. This is my code while ($line=<inputfile>){chomp $line; $string=$string.$line;}A second option according to google is to use /m or /s modifiers. But the problem is that I dont know where the text would be broken by the newline so should I put a . after every character in my regular expression? My actual expression is pretty long so I dont know if that would be the best way to do it. My regular expression is to search for a keyword and capture the 5 characters before and after it with the keyword also containing a random 10 character sequence in it. $string =~ /(?<=(.....))abc(.{10})def(?=(.....))/gI am assuming that there is something obvious I am missing here so would appreciate any help. ThanksIn reply to Regular expressions across multiple lines by abcd
|
|