aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes I have some questions about java.util.regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "I have some questions about java.util.regex" Watch "I have some questions about java.util.regex" New topic
Author

I have some questions about java.util.regex

chrislxd roger
Greenhorn

Joined: Nov 10, 2013
Posts: 3
I want to find Hexadecimal number from a String.So I write this code



But Print is "MATCH:",I don't know where trouble is?Can somebody helps me,please?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41574
    
  54
That's not how the \xhh feature works. It doesn't match the hex notation like "0x56", it matches the actual hex character. And the character to match would be specified using the two "hh" digits. So if you want to match the character "A" like this, you use "\x41".

Matching the notation can be done with something like "0x[\da-fA-F]{2}".


Ping & DNS - my free Android networking tools app
chrislxd roger
Greenhorn

Joined: Nov 10, 2013
Posts: 3
Thank you!!!It works.But I really want to know where to use "\xhh".May be an example.Thank you again!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41574
    
  54
Like this:

Note that hex 41 = decimal 65 = ASCII 'A'.

Of course, for 'A' this is not very useful, because A matches itself if you include it directly in a regexp. But for non-printable control characters that do not have a special regexp pattern (like vertical tab hex 0B) this is useful.
chrislxd roger
Greenhorn

Joined: Nov 10, 2013
Posts: 3
oh~I see.I appreciate your detailed explanation. ^_^
 
Don't get me started about those stupid light bulbs.
 
subject: I have some questions about java.util.regex