"Daniel F. Savarese" wrote: > > In message <[EMAIL PROTECTED]>, Michael Davey - Sun UK Support Engineer > writes: > >I am not sure I understand your response. Let's ignore \a, \b, \e and > >\v for now. How does substitute() parse the input string? > > "s/foo/bar/" is split up into its components first, taking into account > any escaped delimiters. > foo is a regular expression, so Perl5Compiler compiles the expression > if it is not already cached. Therefore all Perl escapes are handled. > bar is the replacement string and is therefore not touched by Perl5Compiler. > If it contains nothing that needs special treatment, it is a handled > by a StringSubstitution (i.e., a normal Java string included verbatim). > If it contains something special, it is handled by Perl5Substitution, so > any group interpolations (e.g., $1, $2) are processed and also the case > modification escapes (\u\U\e\E). The case modification escapes used > to not be handled because they are a part of normal Perl string > processing and were considered out of scope. But Mark made a convincing > argument to include them and provided a patch to boot, so they are now > handled. > > The gist of it is that if you use "\\t" in the replacement string it is > a vanilla Java string and treated as '\' followed by 't', so you would use > "\t" if you really wanted a tab to be substituted.
Thanks for your reply regarding the input string - that has helped a lot. Now, if I have: perl -e '$a="\x23\x41\x23"; $a =~ s/\x41/\x42/; print $a;' In Java I would do: // assume Java \u00NN is equivalent to Perl \xNN input = new PatternMatcherInput ( "\u0023\u0041\u0023" ); result = perl.substitute( "s/\\x41/\\x42/", input); I expect the Perl replacement string (with an extra backslash for Java) to be interpreted and for result to hold "#B#". But I get "#x42#", suggesting that \\xNN is parsed in the replacement string. -- Michael -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
