in reply to Regular Expression: search two times for the same number of any signs
you can play with length and more less greediness like in the following example (for sure while i'm writing you had received better answers)
use strict; use warnings; while (<DATA>){ chomp; $_=~/x(.*?)x(.*)x$/; if (length $1 == length $2){ print "OK $_\t [$1]",length $1," [$2]",length $2,"\n"; } else{print "$_ NOT OK\t[$1]",length $1," [$2]",length $2,"\n";} } __DATA__ xxx x.x.x x12x..x x123x...x x123x.x.x x12x1x # out OK xxx []0 []0 OK x.x.x [.]1 [.]1 OK x12x..x [12]2 [..]2 OK x123x...x [123]3 [...]3 OK x123x.x.x [123]3 [.x.]3 x12x1x NOT OK [12]2 [1]1
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular Expression: search two times for the same number of any signs
by Anonymous Monk on Nov 29, 2016 at 10:37 UTC | |
by Discipulus (Canon) on Nov 29, 2016 at 12:23 UTC |