?
Solved

Perl pattern match a hexadecimal number

Posted on 2006-03-27
1
Medium Priority
?
836 Views
Last Modified: 2012-06-21
Hello,

How can I extract the following value, 0xF and 9.

$line="This is a hexadecimal number 0xF";
$line="This is a hexadecimal number 9";

I want to be able to extract 0xF and 9 via pattern matching even though the 9 does not have a 0x in front of it.  

I would like to be able to store the hexadecimal number in a perl variable such as $1.
Maybe something like this:
$line=~/This is a hexadecimal number (?)/;
print "The hexadecimal number is $1;

Thanks
0
Comment
Question by:carlos8888
1 Comment
 
LVL 85

Accepted Solution

by:
ozo earned 200 total points
ID: 16302969
$line=~/This is a hexadecimal number (\w+)/;
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question