aefxx wrote:
> Hi everybody.
>
> I just wanted to leave a note on regular expression in java.
> In one of my projects I had to match hex digits in a string.
>
> Say, u want to search for 0x00 in a string, u would likely
> search for the escape sequence in the API and find "\xhh"
> with hh being the digits to search for.
>
> Well, if done like this u would get an error, being told
> that \x is not a valid escape sequence.
> Actually u dont have to escape the x but the backslash.
>
> So, it should look like this in the end: "\\x00".
> This works fine for me. Hope I saved some people some
> head scratching.
Actually, you are escaping the second \ with the first to make a single \ in
the java String. The single \ thus created is escaping the x so as to
indicate a hex value withing the regex.
- Virgil
|