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

Re: Removing digits from a string

by Anonymous Monk
on Jan 01, 2013 at 10:53 UTC ( #1011137=note: print w/ replies, xml ) Need Help??


in reply to Removing digits from a string

s/\d+//


Comment on Re: Removing digits from a string
Re^2: Removing digits from a string
by erix (Priest) on Jan 01, 2013 at 10:56 UTC
    s/^\d+// # 'first few digits'
      s/^\D*\d+// # 'first few digits'

        That's likely not the right interpretation of his use of 'truncate', which suggests outer positions, no? But I guess the OP should be able to 'figure' it out ;-)

        s/^\D*\d+// # 'first few digits'

        Even if this interpretation is correct (and I agree with erix that it’s unlikely), there is no warrant in the OP to remove the non-digit prefix. So the regex would need to be: s/^(\D*)\d+/$1/. For example:

        23:21 >perl -wE "$f = 'xyz20130101Customer100.imp'; $f =~ s/^(\D*)\d+/ +$1/; say $f;" xyzCustomer100.imp 23:22 >

        Update (2nd January, 2013):

        Thank-you Anonymous Monk for the improvement below using \K: shorter and “much more efficient”, according to perlre. I’ve learned something useful!

        Hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (17)
As of 2014-04-18 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (469 votes), past polls