Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: $1 and regex

by tmiklas (Hermit)
on Aug 27, 2002 at 07:22 UTC ( #193089=note: print w/replies, xml ) Need Help??


in reply to $1 and regex

If I understand you well, your input line looks like '3256 nothing special 356216'. In this case it's enough to match digit, non-digit and digit again...

#!/usr/bin/perl while (<>) { print if m/(\d+)\D+(\d+)/; print "$1\n$2\n"; }
The output is:
tm@norad:~$ ./regex_test 123 testing... testing 456 123 testing... testing 456 123 456
UPDATE: after reading next replies...
  1. .+ isn't the best notation - it shouldn't catch next digits after (\d+) but it's not specially safe AIMO, especially makes the code more difficoult to understand
  2. this 'to', whitespaces or other words you mentioned in your problem are covered with \D+ which IMvHO is more universal becouse of catching anything except digits

Greetz, Tom.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://193089]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-05-28 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (99 votes). Check out past polls.

    Notices?