Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: addd spaces after caps & reduce whitespace to single space

by prasadbabu (Prior)
on Feb 19, 2005 at 15:37 UTC ( [id://432731]=note: print w/replies, xml ) Need Help??


in reply to Re: addd spaces after caps & reduce whitespace to single space
in thread addd spaces after caps & reduce whitespace to single space

Sht1tn OP has asked that white space is not allowed at the beginning of the sentence.

Also he asked more that one spaces or tabs or newlines.

So your answers wont work for the above conditions.

update:when you are updating your node, use update in your node.

Prasad

  • Comment on Re^2: addd spaces after caps & reduce whitespace to single space

Replies are listed 'Best First'.
Re^3: addd spaces after caps & reduce whitespace to single space
by sh1tn (Priest) on Feb 19, 2005 at 16:06 UTC
    IMHO - no need for $1 and $2 capturing:
    $string =~ s/(?<=.)([A-Z])/ $1/g;


      As long as you're doing that ...

      $ perl -e '$s="JustAnotherPerlHacker\n"; $s=~s/(?<=.)(?=[A-Z])/ /g; pr +int $s' Just Another Perl Hacker
      By using zero-width assertions on both sides, we don't need to actually match anything. We're matching, literally, zero characters - we're matching simply a location with no length associated. Note, however, that I would make it just a bit different for a bit more flexibility:

      $s=~s/(?<=\S)(?=[[:upper:]])/ /g

      Match the location between a non-space and a capital letter. Using a character class gives us flexibility for other languages.

      This may also be useful for splitting:

      $ perl -e '$s="JustAnotherPerlHacker\n"; @a = split /(?<=\S)(?=[[:uppe +r:]])/, $s; print "@a"' Just Another Perl Hacker
      Since split is splitting on nothing, there is nothing actually removed.

      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found