in reply to arithmetic in a regex ?
I would search for a number followed by a char followed by another number using a regexp, and then filter in perl:
#!/usr/bin/perl use strict; use warnings; use feature 'say'; my $text='abc 1foo 1x1 ee2 3B4 n 5 6t7 q9q 5+6'; while ($text=~/(\d)([[:alpha:]])(\d)/g) { if ($1 + 1 == $3) { say "$1$2$3 is wanted because $1 + 1 = $3"; } else { say "$1$2$3 matches, but is not wanted ($1 + 1 != $3)" +; } }
Output:
1x1 matches, but is not wanted (1 + 1 != 1) 3B4 is wanted because 3 + 1 = 4 6t7 is wanted because 6 + 1 = 7
Alexander
|
|---|