> >>>Note: I realised that I had to remove the ^ before the & as this was
> >>>only included to make the command valid to the Windows 2000 command
[quoted text clipped - 13 lines]
> The string to compile is just a string. The only thing that has to be
> escaped is the backslash. So every backslash in the pattern must be doubled.
There's more to it than that. Characters also have to be escaped within
the regular expression in order to be compiled by the regexp compiler.
These characters are also escaped by using a backslash.
See my response to Nemo's post, where I have to use three backslashes to
escape a double-quote character. A regexp compiler would expect a
double-quote to be passed as \", but so would the Java compiler, which
in addition expects the backslash itself to be escaped. Hence the need
for \\\"
Thanks for your reply.
Regards,
Jonny
Dale King - 06 Jun 2005 04:12 GMT
>>>>>Note: I realised that I had to remove the ^ before the & as this was
>>>>>only included to make the command valid to the Windows 2000 command
[quoted text clipped - 17 lines]
> the regular expression in order to be compiled by the regexp compiler.
> These characters are also escaped by using a backslash.
I assume he knew that. I was referring to what had to be escaped on top
of the normal regular expression escapes.
> See my response to Nemo's post, where I have to use three backslashes to
> escape a double-quote character. A regexp compiler would expect a
> double-quote to be passed as \", but so would the Java compiler, which
> in addition expects the backslash itself to be escaped. Hence the need
> for \\\"
D'oh. Yes forgot to mention the quote. My point was that the thing that
really trips people up is the fact that backslashes must be escaped.
I really wish they would adopt an alternate way to allow you to specify
strings that would let you get around the escaping for things like
regular expressions and path names. Such a thing has been proposed here
before:
<http://groups-beta.google.com/group/comp.lang.java.programmer/browse_frm/thread/
2ae847810dfcb8e1>

Signature
Dale King
Nemo - 08 Jun 2005 00:48 GMT
>See my response to Nemo's post, where I have to use three backslashes to
>escape a double-quote character. A regexp compiler would expect a
>double-quote to be passed as \", but so would the Java compiler, which
Are you sure that you need to quote " in an RE?
However, it won't do any harm, if not required.
I now realise my previous posting was a bit ambiguous/incomplete.
I quoted the " but left off the enclosing " and " - all of which are
needed to turn it into a Java String.
I should have written:
String pattern="href=\"(.*?)\"";
OK?