Search replace for title casing
-
Fellow Notepad++ Users,
Could you please help me the the following search-and-replace problem I am having?
I have some words between an specific xml tagset that I need title cased. Ie first letter of each word uppercased. However, I want to do this through files and the amount of words between the specific tagset differs.
Here is the data I currently have (“before” data):
<tag> one two three </tag> <tag> one two three four </tag>Here is how I would like that data to look (“after” data):
<tag> One Two Three </tag> <tag> One Two Three Four </tag>I know to do one word for title casing, you can use the expression:
- Find What =
\<(\w+) - Replace With =
\L \u \1 - Search Mode = REGULAR EXPRESSION
If it was a specific number of words I would just do capture groups but I’m not sure how to do multiple words at once if the amount of words is changing.
Could i get some help on this please?
Thanks!
- Find What =
-
Thanks for following the search-replace-question-template.
We have a generic regex formula for “Replace in a Specific Zone of Text”. You want to do multiple replacements inside the zone of
<tag>to</tag>. In the nomenclature of that recipe, BSR would be<tag>, ESR would be</tag>, and your FIND WHAT and REPLACE WITH correspond to the FR and RR from the recipe.Putting it all together:
- FIND WHAT =
(?-si:<tag>|(?!\A)\G)(?s-i:(?!</tag>).)*?\K(?-si:\<(\w+)) - REPLACE WITH =
\L\u\1 - Search Mode = REGULAR EXPRESSION
I believe that should work (at least with your simple data
(If the tags actually might have attributes,
<tag[^>]*>might be required) - FIND WHAT =
-
I can suggest an “unconventional” way to do this. It requires a plugin, Columns++, which you can install from Plugins | Plugins admin….
With no text selected, from the Columns++ menu, select Search… and enter:
Find what:
<tag>\K[^<]++(?=</tag>)
Search mode: Regular expressionin the dialog. Next, click the drop-down arrow at the right end of the Count button and choose Select All from the menu.
Now close the dialog; then, from the main Notepad++ menu, choose Edit | Convert Case to | Proper Case.
-
Awesome thank yall for the help!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login