perl-unicode

Re: UTF-16LE fails in substitution

2005-09-23 02:52:45

Minor tweak to the regex substitution in that "subroutine version" that I 
posted previously -- it should be:

    $editdata =~ s/(\x{feff}?(?:<\?.*?\?>\s*)*)/$1$comment/s;

(note the optional BOM at the beginning of the match pattern -- if the data
contains a BOM, then $comment will be inserted after it).  As before, if 
nothing in the data matches the pattern, then $comment will be inserted at 
the beginning of the string.

If you make sure that the original data contains at least one "<?...?>"
string, change the final "*" to "+", and then add a test to check whether
the substitution succeeded.

        Dave Graff


<Prev in Thread] Current Thread [Next in Thread>