regex - Continue with newline in perl -


i have perl script this:

elsif ($url =~ m/^(http|https):\/\/(banner(s?)|advertising|iklan|adsbox|adserver|adservice(s?))\.(.*)/) {         print "http:\/\/ip\.mdm\-lo\-00\.willsz\.net/null\.png\n"; } 

that working redirect squid (one line), if change multiline this, absolutely not working.

elsif ($url =~ m/^(http|https):\/\/(banner(s?) \  |advertising \  |iklan \  |adsbox \  |adserver \  |adservice(s?))\.(.*)/) {     print "http:\/\/ip\.mdm\-lo\-00\.willsz\.net/null\.png\n"; } 

any suggestion? - thank you

you getting little carried away escapes , parentheses! , simpler change delimiter {...} isn't in body of pattern; don't have escape slashes

unless use /x modifier, whitespace significant in regex pattern, including newlines, , escaping them makes no difference @ all. isn't c!

you should use non-capturing parentheses (?:...) unless need capture substrings of matched pattern

and there no need throw-away .* match tail of string, unless need match , capture further use

your best option use m{...}x. can add spaces, tabs, , newlines make pattern clearer

and backslashes aren't necessary in double-quoted strings @ all, unless want add special characters \t tab, \n newline etc.

this code should want

elsif ( $url =~ m{ ^ https?:// (?:         banners?    |         advertising |         iklan       |         adsbox      |         adserver    |         adservices? ) \. }x ) {      print "http://ip.mdm-lo-00.willsz.net/null.png\n"; } 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -