Removing characters once a series stops

J

Jim

I have strings that I need to get the first set of numbers from. IE:

ABC123DEF
ABC11JH8KLZ

I need to get 123 and 11 from the from the above strings. I can strip
the first characters off with =~ s/\D*//; but how do I strip off
everything else, even any additional numbers, after the first set of
numbers ends? Thanks!

J
 
S

Sara

I have strings that I need to get the first set of numbers from. IE:

ABC123DEF
ABC11JH8KLZ

I need to get 123 and 11 from the from the above strings. I can strip
the first characters off with =~ s/\D*//; but how do I strip off
everything else, even any additional numbers, after the first set of
numbers ends? Thanks!

J

Hello Jim:

Let's see here, how about

s/^\D*(\d+).+$/$1/;

Have a super weekend!
Gx
 
M

Michael P. Broida

Sara said:
Hello Jim:

Let's see here, how about

s/^\D*(\d+).+$/$1/;

Hmm, that requires at least one character AFTER the initial
number group. That fits the examples, but not necessarily
ALL of the data that will be encountered.

Perhaps just change the ".+" to ".*" ?? THAT will fit the
examples AND any other data with nothing after the initial
number group.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top