$1 in reg ex

Posted on 2002-05-20
Last Modified: 2010-03-05
What does this mean

$var =~ s/\D*(\d+)\D*/$1/;
Question by:castello
  • 2

Accepted Solution

bebonham earned 50 total points
ID: 7022159
it means

dasljda123123lkajslsjad  would become


it looks for a string that might have some stuff at the begenning or at the end or both and definitely has to have at least 1 number in it, and then it removes everything except for the number. and then the $var is just the number


Expert Comment

ID: 7022162
$1 is a reference to whatever is in side the first set of ()

Expert Comment

ID: 7022302
it's true that $1 is the string matched in the first use of the braces, but when using this within the regexp it's more elegent to use \1 instead.
LVL 84

Expert Comment

ID: 7023280
Since it's not used within the regexp here, $1 is correct in the substitution

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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 (…
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

12 Experts available now in Live!

Get 1:1 Help Now