regex for multiple strings -
i have 2 strings i'm trying match in file , return line.
the first string match i'm looking not completely.
example:
i might looking matcht in matchthisstring match not entire string.
string 1 might come before or after string 2 , might start uppercase or lower case letter.
example:
i might looking have actually.
but , have things matchthisstring.actually or actually.matchthisstring or matchthisstring.someotherjunkidon'tcareabout.actually other combinations that.
i'm having problems using 2 search strings , getting reggae work.
here's example of code works:
@matches; while (<$in_fh>) { #push @matches, $_ if / \q$wanted\e .* \q$prefix\e /x; #push @matches, $_ if / \q^*(.*)$wanted\s*(.*)\e .* \q^*(.*)$prefix\s*(.*)\e /x; push @matches, $_ if / \q$wanted\e /x; }
what want work 1 of other options that's commented out. don't think i'm joining 2 searches 1 string properly.
thanks in advance assistance.
sounds want
push @matches, $_ if /\q$wanted\e/ , /\q$prefix\e/;
demo:
$ perl -ne 'use strict; use warnings; use vars qw($wanted $prefix @matches); > begin { $wanted = "/donate"; $prefix = "lghfound"; } > push @matches, $_ if /\q$wanted\e/ , /\q$prefix\e/; print @matches' <<'here' > http://www.google.com/donate > http://lghfoundation.com/pages/donate.html > http://example.com > here http://lghfoundation.com/pages/donate.html http://lghfoundation.com/pages/donate.html
Comments
Post a Comment