How do I match something like this using perl regex? -
the file looks like
[n computer end] [m whatever] [n look] [n why not]
i need words in bracket start [n
here want computer end why not may or may not in same line
i tried this:
if($line =~/\[n(.+?)\]/)
but match first 1 of each line.
use g
modifier on regular expression "g"lobal matches. either this:
while ($line =~ /\[n(.+?)\]/g) { # $1 contains text between "[n" , "]" }
or this:
my @matches = $line =~ /\[n(.+?)\]/g; # @matches contains of matching items of text
Comments
Post a Comment