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 Java 8 in Action this week in the Java 8 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: 39575
    
  27
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 - updated with new look and Ping home screen widget
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: 39575
    
  27
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. ^_^
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I have some questions about java.util.regex
 
Similar Threads
null exception!
Doubt in String class
Problem using StringTokenizer
Searching and replacing text in a string
Recursion: returning a value/not returning a value(void)