• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using \U \L in regular expressions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using \U \L in regular expressions


  • Subject: Re: Using \U \L in regular expressions
  • From: "Mark J. Reed" <email@hidden>
  • Date: Thu, 13 Aug 2009 19:20:15 -0400

Outside of Perl and (GNU) sed, I'm not sure what tools support those.

$ sed -e 's/\(.\)\(.*\)/\1\L\2/' <<<HELLO  ==> Hello

$ perl -pe 's/(.)(.*)/\1\L\2/' <<<HELLO ==> Hello

Ruby doesn't... you have to use the block form of replacement:

$ ruby -pe '$_.sub!(/(.)(.*)/) { $1 + $2.downcase }' <<<HELLO  ==> Hello

But for this particular job it's much easier to just use the capitalize method:

$ ruby -pe '$_.capitalize!' <<<HELLO  ==> Hello

Likewise Python, with the title method:

$ python -c 'import sys; print sys.stdin.readline().strip().title()'
<<<HELLO ==> Hello

--
Mark J. Reed <email@hidden>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Using \U \L in regular expressions
      • From: email@hidden (Randal L. Schwartz)
References: 
 >Using \U \L in regular expressions (From: Tim Mansour <email@hidden>)
 >Re: Using \U \L in regular expressions (From: Emmanuel LEVY <email@hidden>)
 >Re: Using \U \L in regular expressions (From: Tim Mansour <email@hidden>)

  • Prev by Date: Re: Using \U \L in regular expressions
  • Next by Date: Re: Using \U \L in regular expressions
  • Previous by thread: Re: Using \U \L in regular expressions
  • Next by thread: Re: Using \U \L in regular expressions
  • Index(es):
    • Date
    • Thread