Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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+//

Replies are listed 'Best First'.
Re^2: Removing digits from a string
by erix (Parson) on Jan 01, 2013 at 10:56 UTC
    s/^\d+// # 'first few digits'
      s/^\D*\d+// # 'first few digits'
        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,

        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 ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011137]
help
Chatterbox?
[Discipulus]: Corion are you would able to realize such thing? O_O
[Corion]: In the same vein I have a script that automates Firefox to enter some data into another system. It's not faster than the people using the script if they were to do it manually, but they prefer not having to check the data and not having typos when ...
[Corion]: ... entering the data
[Corion]: Discipulus: I don't know whether I could really do that, but the init process itself mostly launches other processes, and the whole startup is just following a path of dependencies and making sure they are all running. Which basically is what ...
[Discipulus]: when at work my time is (temporarly) owned by the firm, so i do not care (coworkers whatch movies.. I code Perl)
[Corion]: ... make already does, except for files instead of programs. But maybe with some /proc hackery, that could be eliminated and one could use plain make :-D
[choroba]: systemd just makes is asynchronous
[choroba]: so, make -j
[Corion]: Discipulus: Yeah - but when writing Perl to save time (instead of having fun), it helps to look whether you're actually saving time ;) Why spend 5 minutes doing manually what you can spend three years automating? ;)
[Corion]: choroba: Oh, yeah :-D

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-07-27 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (408 votes). Check out past polls.