Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Space between digits

by Anonymous Monk
on Nov 21, 2012 at 21:17 UTC ( [id://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 (Canon) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-19 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found