#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Convert ALL UPPER CASE to Sentence Case


    I want to convert ALL UPPER CASE to Sentence Case the text between h1 tag below (the text varies on every page), how can I do this?


    Code:
    <h1>ORTA YAŞLARDA TOPLUMSAL YAŞAM</h1>
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,295
    Rep Power
    9400
    1. Extract the text using whatever you want
    2. Convert it all to lowercase
    3. Use a regex to replace the first letter of each "word", however you define that, with itself capitalized. You'll need help from your programming language to do that

    What programming language?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Yes, not easy as a pure regex.

    An example using Perl:

    Perl Code:
    $string = lc $string; # everything to lower case
    $string =~ s/\b(\w)/uc($1)/ge; # first letter of words to upper case


    Depending on your locale setup for Unicode in your language, you might have specific problems with special characters such as 'Ş'.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0
    I use Powergrep to replace batch text. I guess first I should find the text using <h1>([^>]+)</h1> then what command to put in replace section to convert them lower case?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Code:
    <h1>([^>]+)</h1>
    You probably want this somewhat safer version:

    Code:
    <h1>([^<]+)</h1>
    For the rest, I do not know how to change case this with Powergrep, so I can't help you on this part.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0
    Okay this powergrep guide worked.

    http://www.powergrep.com/manual/xmpcapwords.html

IMN logo majestic logo threadwatch logo seochat tools logo