in reply to Regex lookahead, lookbehind
#!/usr/bin/perl use warnings; use strict; while (<DATA>) { print "$. ok\n" if /^foo # "foo" _ # followed by "underscore" (?:bar|test) # followed by "bar|test" (bar or tes +t) _ # followed by "underscore" ((?:\w+\.)+) # followed by alhpnum string with # dot at end (like foo10.1.1.1) \1? # followed by one or zero occurences # of same alhpnum string (like # foo10.1.1.1) followed by dot \w{1,10} # followed by 1-10 characters, # containing at least one digit and # one letter and underscore (e.g. # TEST_test, TEST_test2, # TEST1_test2) \.txt$ # ends with .txt /x; } __DATA__ foo_bar_foo10.1.1.1.TEST.txt foo_test_foo10.1.1.1.foo10.1.1.1.TEST_test.txt
To test the condition "at least one digit and one letter and underscore", I'd probably capture the group and test these conditions independently:
/\d/ && /[[:alpha:]]/ && /_/
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex lookahead, lookbehind
by rahulme81 (Sexton) on Feb 23, 2017 at 09:25 UTC | |
by choroba (Cardinal) on Feb 23, 2017 at 10:04 UTC | |
by rahulme81 (Sexton) on Feb 23, 2017 at 11:40 UTC | |
by choroba (Cardinal) on Feb 23, 2017 at 12:18 UTC | |
by haukex (Archbishop) on Feb 23, 2017 at 10:33 UTC |