E
E
EGDFree2013-11-29 11:55:43
Perl
EGDFree, 2013-11-29 11:55:43

Word border and symbol +

Good afternoon.
Pseudocode in Perl:

$t = "C++, Java; JavaScript, c++, java; Oracle. Perl - power.";
$t =~ s/\b\Qc++\E/!!!Perl!!!/ig;
print $t, "\n";

The replacement works fine, but if you replace the pattern with "\b\Qc++\E\b" (that is, add an anchor at the end), then no more matches are found.
Please tell me what I don't understand here.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Blokhin, 2013-11-29
@EGDFree

$t = "C++, Java; JavaScript, c++1, java; Oracle. Perl - power.";
$t =~ s/\b\Qc++\E(?=\W)/!!!Perl!!!/ig;
print $t, "\n";

\b - word boundary
\w - alphanumeric character (any letter, digit, or underscore)
\W - any character other than letters, numbers, and the underscore
perl considers a point between \w and \W to be a word boundary, regardless of the order in which these characters appear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question