Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

$1 in reg ex

Posted on 2002-05-20
4
Medium Priority
?
213 Views
Last Modified: 2010-03-05
What does this mean

$var =~ s/\D*(\d+)\D*/$1/;
0
Comment
Question by:castello
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 200 total points
ID: 7022159
it means

dasljda123123lkajslsjad  would become

123123

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

0
 
LVL 8

Expert Comment

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

Expert Comment

by:iddo_levin
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.
0
 
LVL 84

Expert Comment

by:ozo
ID: 7023280
Since it's not used within the regexp here, $1 is correct in the substitution
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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

618 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