views:

791

answers:

1

I'm using Notepad++ to do some text replacement in a 5453-row language file. The format of the file's rows is:

variable.name = Variable Value Over Here, that''s for sure, Really

Double apostrophe is intentional.

I need to convert the value to sentence case, except for the words "Here" and "Really" which are proper and should remain capitalized. As you can see, the case within the value is typically mixed to begin with.

I've worked on this for a little while. All I've got so far is:

 (. )([A-Z])(.+)

which seems to at least select the proper strings. The replacement piece is where I'm struggling.

+1  A: 

Regex replacement cannot execute function (like capitalization) on matches. You'd have to script that, e.g. in PHP or JavaScript. Maybe another editor lets you do that, I haven't seen this feature yet.

I built myself a Web page called Text Utilities to to that sort of things:

  • paste your text
  • go in "Find, regexp & replace" (or press Ctrl+Shift+F)
  • enter your regex (mine would be ^(.*?\=\s*\w)(.*)$)
  • check the "^$ match line limits" option
  • choose "Apply JS function to matches"
  • add arguments (first is the match, then sub patterns), here s, start, rest
  • change the return statement to return start + rest.toLowerCase();

The final function in the text area looks like this:

return function (s, start, rest) {
     return start + rest.toLowerCase();
};

Maybe add some code to capitalize some words like "Really" and "Here".

streetpc
Thanks for the help streetpc. In Notepad++ I can apply the replace function using regex which is suh-weet. Then again, your site is suh-weet too. This pretty much nails it unless I have a new sentence within the variable portion, but I can fix that by finding ". [a-z]" and fixing the case on the first letter following a period-space combination.I'm going to leave the question open for a bit to see if any Notepad++ people respond but you definitely solved my problem. Thanks!
jkramp
You're welcome :)
streetpc