in reply to Re^4: Unicode substitution regex conundrum
in thread Unicode substitution regex conundrum
Hi,
I may be too late, seeing your message has been here since nearly two months, but it could still be of use to you or someone else.
I may be wrong, but it seems to me like the problem does not reside with the whitespaces, but with the definition of word in Perl : \w+ does not match chinese characters.
On my system (with unicode locale and chinese readable in the console) :
Furthermore, I played a bit with your code, and when I replaced
The quickest workaround I see at the moment would be to declare $word using CJK character ranges instead of \w.
Hope I could be of help.
Lu.
I may be wrong, but it seems to me like the problem does not reside with the whitespaces, but with the definition of word in Perl : \w+ does not match chinese characters.
On my system (with unicode locale and chinese readable in the console) :
(Chinese chars were jumbled, I didn't put the codes in the one-liner)$ perl -le 'print "ok" if ("我走" =~ m/\w+/)' $ perl -le 'print "ok" if ("hi" =~ m/\w+/)' ok
Furthermore, I played a bit with your code, and when I replaced
with$terms =~ s/($word)\p{IsSpace}*($word)/$1 AND $2/g for 1..2;
it did the job I expected of it.$terms =~ s/(\p{IsSpace}/ AND /g;
The quickest workaround I see at the moment would be to declare $word using CJK character ranges instead of \w.
Hope I could be of help.
Lu.
In Section
Seekers of Perl Wisdom