Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Regex Help

by Anonymous Monk
on Mar 28, 2013 at 05:51 UTC ( #1025856=note: print w/replies, xml ) Need Help??


in reply to Re: Regex Help
in thread Regex Help

Thanks 2teez, Now I have 1 more doubt. pls can u? If the data is like below, how we can do it?
$line = "pirates1 of careebian 100"; $line = "pirates2 of careebian 100"; $line = "pirates3 of careebian 100";
and I need the output as "pirates1 of careebian" & "pirates2 of careebian" & "pirates3 of careebian"

Replies are listed 'Best First'.
Re^3: Regex Help
by 2teez (Priest) on Mar 28, 2013 at 06:21 UTC

    then change this print $1,$/ if/(\D+?)\d+?/;
    to
    this print $1,$/ if/(.+?)\s+?\d+?/;

    UPDATE:
    In case, you have all these data in the same file you can try this:

    use strict; use warnings; while(<DATA>){ chomp; print $1,$/ if/(.+?)(\s+)?\d+?$/; } __DATA__ piratesofcareebian100 pirates of careebian100 pirates of careebian 100 pirates1 of careebian 100 pirates2 of careebian 100 pirates3 of careebian 100

    Output
    piratesofcareebian pirates of careebian pirates of careebian pirates1 of careebian pirates2 of careebian pirates3 of careebian
    Please, check the reference I mentioned in my first post on this thread.
    Hope that helps

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
      Thanks 2Teez. That was clear & fine... :)

        How about "everything from pirates to careebian" ? ;-)

        use strict; use warnings; while(<DATA>){ chomp; print $1,$/ if /(pirates.*careebian)/; } __DATA__ piratesofcareebian100 pirates of careebian100 pirates of careebian 100 pirates1 of careebian 100 pirates2 of careebian 100 pirates3 of careebian 100

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025856]
help
Chatterbox?
[choroba]: timestamps are hard
[1nickt]: not all all yet
[1nickt]: the stable subversion of each major version on the platform I have in my hands most of the day
[Tux]: choroba can't you up the default stack size to 17?
[1nickt]: and I will maybe add the other subversions
[1nickt]: I am on MacOSX and there is a sore lack of testing resources for CPANTS I think
[choroba]: Tux Why? It works for me with 16 :-)
[Tux]: and the defailt is 15?
[choroba]: sorry, typo. Works for me with 15 which is the default

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2017-09-19 20:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (228 votes). Check out past polls.

    Notices?