Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Space between digits

by Anonymous Monk
on Nov 21, 2012 at 21:17 UTC ( #1005011=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi, I am new to perl. I want to know if there is any way to insert space between two numeric patterns. like
0:00 11/21/2012
I need triple space instead of one space between 00 and 11 Thank you

Replies are listed 'Best First'.
Re: Space between digits
by tobyink (Abbot) on Nov 21, 2012 at 21:23 UTC
    use 5.014; my $string = "0:00 11/21/2012"; my $new = $string =~ s/ / /r; say $string; say $new;
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      I meant for that pattern and of date and time. I didnt mean that particular string. for example for the pattern
      (\d+)\:(\d+) (\d+)\/(\d+)\/(\d+)
      how do I triple the space between the time and date ?

        The code I posted will work on any string. It finds the first space and replaces it with three spaces.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Space between digits
by bart (Canon) on Nov 23, 2012 at 12:29 UTC
    This might help:
    s/(?<=\d) (?=\d)/ /
    It replaces a single space with 3 provided there's a digit (at least one) in front of it, and one (at least one) behind it.
      Yes yes that was good one Bart. I tried that and it worked...thank you very much.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1005011]
Approved by tobyink
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2016-07-29 13:23 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (262 votes). Check out past polls.