0

I had a string contains hex value like \x76\x6f\x69\x64\x28\x29 (void()) representation, i would like to search the \x76\x6f\x69\x64\x28\x29 value from above string.

needed java regex pattern for same.

thanks in advance.

5
  • 1
    Why regex? Did you try anything else? Commented Dec 11, 2014 at 8:11
  • What distinguishes the particular strings you are looking for? Commented Dec 11, 2014 at 8:18
  • i had string HYPERLINK "[email protected]'==[window["[email protected]'==[window["location"]='\x6a\x61\x76\x61\x73\x63\x72\x69\x70\x74\x3a\x61\x6c\x65\x72\x74\x2810502\x29']==' want to check if some specific value is present in hex value using java regex Commented Dec 11, 2014 at 8:32
  • i had tried using ((J|\%6A|\x6A)(A|\%61|\x61)(V|\%76|\x76)(A|\%61|\x61)(S|\%73|\x73)(C|\%63|\x63)(R|\%72|\x72)(I|\%69|\x69)(P|\%70|\x70)(T|\%74\x74)(:|\%3A|\x3A)) this pattern, but don't work for \x scenario Commented Dec 11, 2014 at 8:34
  • does java support regex pattern to find hex string ? Commented Dec 11, 2014 at 8:34

1 Answer 1

1

Since this appears to be some sort of debugger output, I'm assuming that you mean a string with escape sequences rather than the characters these escape sequences represent. In that case:

String s = "\\x76\\x6f\\x69\\x64\\x28\\x29 (void())";
String s2 = s.replaceAll("^((\\\\x[0-9a-f]{2})+) .*$", "$1");

Where \\x[0-9a-f]{2} (properly escaped for Java strings) matches a character sequence, and from there it's just ^(sequence+) .*$, i.e., matching the sequence several times, capturing it (in $1), and discarding the rest of the string.

This assumes that the string starts with the sequence of character sequences. If this is not the case, you will have to remove the ^ (which matches the beginning of the string).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.