In the Web and in different books everybody can find smth like "connon regex lists" containig dozens of reallife regular expressions simple enough to be understood by everybody.
Being quite simple, these regexes are generally used to solve routine problems every Perl programmer meet.
But there are some tasks, which require regular expressions of much more complexity.
I want to make a list of complicated (obfuscated, odd etc.) regular expressions used to solve diffucult real problems (and then i plan to make it availible online somewhere outside this thread :) ). I will be very obliged if you post here examples of your most interesting regexes combined with chunks of data they were intended to match against.
Of course, i didn't type the second regex myself; it is generated by my substructure search engine for the
as a response to a usual request. That's why i used the word "created" instead of "wrote" in the title — some interesting regexes are never typed, but are used intensively :)
The regex (be stricter, this mix of regex and perl code ;)) in the heart of this short script finds all triangles for
quest and puts them all in the %x hash.
As this is a complete Perl script (the forking regex standalone has no sense), i have put it under
too.
sub valid {
my $spot = substr($grid_h, $_[0]*$size+$_[1], 1);
return 1 if $spot eq $_[2];
return if $spot ne '_';
return if index(substr($grid_h, $_[0] * $size, $size), $_[2]) >= 0;
return if index(substr($grid_v, $_[1] * $size, $size), $_[2]) >= 0;
return 1;
}
$re = qr/
(?:
(?(?{ !valid(0, 0, '1') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '1')
+; }) |
(?(?{ !valid(0, 0, '2') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '2')
+; }) |
(?(?{ !valid(0, 0, '3') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '3')
+; }) |
(?(?{ !valid(0, 0, '4') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '4')
+; }) |
(?(?{ !valid(0, 0, '5') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '5')
+; }) |
(?(?{ !valid(0, 0, '6') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '6')
+; }) |
(?(?{ !valid(0, 0, '7') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '7')
+; }) |
(?(?{ !valid(0, 0, '8') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '8')
+; }) |
(?(?{ !valid(0, 0, '9') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 0, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '9')
+; })
)
(?:
(?(?{ !valid(0, 1, '1') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '1')
+; }) |
(?(?{ !valid(0, 1, '2') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '2')
+; }) |
(?(?{ !valid(0, 1, '3') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '3')
+; }) |
(?(?{ !valid(0, 1, '4') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '4')
+; }) |
(?(?{ !valid(0, 1, '5') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '5')
+; }) |
(?(?{ !valid(0, 1, '6') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '6')
+; }) |
(?(?{ !valid(0, 1, '7') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '7')
+; }) |
(?(?{ !valid(0, 1, '8') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '8')
+; }) |
(?(?{ !valid(0, 1, '9') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 1, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '9')
+; })
)
(?:
(?(?{ !valid(0, 2, '1') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '1'
+); }) |
(?(?{ !valid(0, 2, '2') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '2'
+); }) |
(?(?{ !valid(0, 2, '3') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '3'
+); }) |
(?(?{ !valid(0, 2, '4') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '4'
+); }) |
(?(?{ !valid(0, 2, '5') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '5'
+); }) |
(?(?{ !valid(0, 2, '6') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '6'
+); }) |
(?(?{ !valid(0, 2, '7') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '7'
+); }) |
(?(?{ !valid(0, 2, '8') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '8'
+); }) |
(?(?{ !valid(0, 2, '9') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 2, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '9'
+); })
)
.
.
.
(?:
(?(?{ !valid(8, 6, '1') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '1
+'); }) |
(?(?{ !valid(8, 6, '2') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '2
+'); }) |
(?(?{ !valid(8, 6, '3') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '3
+'); }) |
(?(?{ !valid(8, 6, '4') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '4
+'); }) |
(?(?{ !valid(8, 6, '5') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '5
+'); }) |
(?(?{ !valid(8, 6, '6') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '6
+'); }) |
(?(?{ !valid(8, 6, '7') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '7
+'); }) |
(?(?{ !valid(8, 6, '8') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '8
+'); }) |
(?(?{ !valid(8, 6, '9') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 78, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '9
+'); })
)
(?:
(?(?{ !valid(8, 7, '1') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '1
+'); }) |
(?(?{ !valid(8, 7, '2') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '2
+'); }) |
(?(?{ !valid(8, 7, '3') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '3
+'); }) |
(?(?{ !valid(8, 7, '4') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '4
+'); }) |
(?(?{ !valid(8, 7, '5') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '5
+'); }) |
(?(?{ !valid(8, 7, '6') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '6
+'); }) |
(?(?{ !valid(8, 7, '7') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '7
+'); }) |
(?(?{ !valid(8, 7, '8') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '8
+'); }) |
(?(?{ !valid(8, 7, '9') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 79, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '9
+'); })
)
(?:
(?(?{ !valid(8, 8, '1') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '1
+'); }) |
(?(?{ !valid(8, 8, '2') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '2
+'); }) |
(?(?{ !valid(8, 8, '3') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '3
+'); }) |
(?(?{ !valid(8, 8, '4') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '4
+'); }) |
(?(?{ !valid(8, 8, '5') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '5
+'); }) |
(?(?{ !valid(8, 8, '6') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '6
+'); }) |
(?(?{ !valid(8, 8, '7') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '7
+'); }) |
(?(?{ !valid(8, 8, '8') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '8
+'); }) |
(?(?{ !valid(8, 8, '9') })x)(?{ local $grid_h = $grid_h; substr($gr
+id_h, 80, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '9
+'); })
)
(?{ $match_grid = $grid_h })
/x;