Hello nikolay,
I would store the exceptions in two hashes, then use exists to test whether a given word should be excluded. I begin by splitting the input string on whitespace. Note the presence of a capture group in the regular expression given to split: the captured string (in this case, the whitespace) is added to the list returned by split, to enable the string to be reassembled correctly after the substitutions have been performed.
#! perl use strict; use warnings; my %exclude_left = map { lc $_ => undef } qw( web 2 ); my %exclude_right = map { lc $_ => undef } qw( program call ); my $z = 'Web-developer, perl-program, explicit-element, function-call, + 2-x speed.'; my @phrases = split /(\s+)/, $z; for (@phrases) { # 1 2 3 <-- capture groups if (/ ( (\w+) - (\w+) ) /x) { my ($phrase, $left, $right) = ($1, $2, $3); s/$phrase/$right-$left/ unless exists $exclude_left {lc $left +} || exists $exclude_right{lc $right +}; } } print '|', join('', @phrases), "|\n";
Output:
17:36 >perl 1667_SoPW.pl |Web-developer, perl-program, element-explicit, function-call, 2-x spe +ed.| 17:36 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: RegExp: words exceptions list similar to characters' one.
by Athanasius
in thread [CLOSED] RegExp: words excepstions list similar to characters' one.
by nikolay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |