Perl pattern match a hexadecimal number

Posted on 2006-03-27
Last Modified: 2012-06-21

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;

Question by:carlos8888
    1 Comment
    LVL 84

    Accepted Solution

    $line=~/This is a hexadecimal number (\w+)/;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    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…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now