Community
    • Login

    Search replace for title casing

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 445 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      Acme1235
      last edited by

      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!

      PeterJonesP CoisesC 2 Replies Last reply Reply Quote 2
      • PeterJonesP Offline
        PeterJones @Acme1235
        last edited by

        @Acme1235 ,

        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)

        1 Reply Last reply Reply Quote 3
        • CoisesC Online
          Coises @Acme1235
          last edited by

          @Acme1235

          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 expression

          in 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.

          1 Reply Last reply Reply Quote 3
          • A Offline
            Acme1235
            last edited by

            Awesome thank yall for the help!

            1 Reply Last reply Reply Quote 0

            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
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors