Community
    • Login

    Newbie find and replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 1.3k 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.
    • Tony HagerT Offline
      Tony Hager
      last edited by

      I’ve read the tutorials and several of the questions from others to try and figure this out, I have gotten close by being able to find my strings but I can’t seem to get the replacement to work correctly.

      Current lines:
      BuildingAreaSource Character,75,Values
      BuildingNumber Character,5,
      BuildingUse Character,1000,Values
      BusinessName Character,40,
      BuyersAgencyCommission Character,10,
      CancelledDate DateTime,10,
      CapitalizationRate Decimal,7,

      I need to end up with:
      BuildingAreaSource Character(75),
      BuildingNumber Character(5),
      BuildingUse Character(1000),
      BusinessName Character(40),
      BuyersAgencyCommission Character(10),
      CancelledDate DateTime(10),
      CapitalizationRate Decimal(7),

      This is what I was using:
      Find what: ,[0-9]+,
      Replace with: (\1),

      Result from this search just deletes my numerals and leaves one comma

      How can I get it to put the numerals back with the ()

      TIA

      Scott SumnerS 1 Reply Last reply Reply Quote 2
      • Scott SumnerS Offline
        Scott Sumner @Tony Hager
        last edited by

        @Tony-Hager

        Well you have a few problems with your regex…one big one is that in the replace expression you reference a group # that doesn’t exist because you didn’t use capturing parentheses in your find expression…

        Maybe try this:

        Find what zone: ,(\d+),(?:Values)?$
        Replace with zone: \(\1\),
        Search mode: Regular expression

        Here’s an explanation of how it works:

        THE FIND EXPRESSION:
        ,(\d+),(?:Values)?$

        • Match the character “,” literally ,
        • Match the regex below and capture its match into backreference number 1 (\d+)
          • Match a single character that is a “digit” (any symbol with a decimal value in the active code page) \d+
            • Between one and unlimited times, as many times as possible, giving back as needed (greedy) +
        • Match the character “,” literally ,
        • Match the regular expression below (?:Values)?
          • Between zero and one times, as many times as possible, giving back as needed (greedy) ?
          • Match the character string “Values” literally (case sensitive) Values
        • Assert position at the end of a line (at the end of the string or before a line break character) (carriage return and line feed, form feed) $

        THE REPLACE EXPRESSION:
        \(\1\),

        • Insert an opening parenthesis \(
        • Insert the text that was last matched by capturing group number 1 \1
        • Insert a closing parenthesis \)
        • Insert the character “,” literally ,

        Created with RegexBuddy

        1 Reply Last reply Reply Quote 2
        • Tony HagerT Offline
          Tony Hager
          last edited by

          Thank you very much!

          1 Reply Last reply Reply Quote 1

          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