• Login
Community
  • Login

Wildcard Find/Replace with numerous lines in between?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
2 Posts 2 Posters 3.4k Views
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.
  • M
    Michael Beck
    last edited by Jan 9, 2023, 3:27 PM

    Find/Replace with a wildcard that could span multiple lines.

    Found a mistake in a JSON that would end up with me having to hand edit about 35,000 lines by hand. OR I assume I could somehow wildcard it but I have never touched RegEx in my life. Desperately looking to salvage my work day LOL

    Basically I need things to END UP like this …

    “items”: [],

    But sadly there are thousands of those that have many lines of data in between those [] brackets that I need to get rid of.

    Example:
    “items”: [
    {
    “amount”: 2,
    “id”: 980333378,
    “position”: 0
    },
    {
    “amount”: 3,
    “id”: 1722154847,
    “position”: 1
    },
    {
    “amount”: 138,
    “id”: 69511070,
    “position”: 2
    }
    ]

    Really has to be a wild card because some entries could have even more fields than what I showed above. Anyone know if this is possible?

    P 1 Reply Last reply Jan 9, 2023, 3:41 PM Reply Quote 0
    • P
      PeterJones @Michael Beck
      last edited by PeterJones Jan 9, 2023, 3:46 PM Jan 9, 2023, 3:41 PM

      @Michael-Beck said in Wildcard Find/Replace with numerous lines in between?:

      Anyone know if this is possible

      Yes, someone knows it is possible.

      Oh, you wanted more than that, eh? ;-)

      Then yes, I know it is possible.

      Still not enough? ;-)

      Use the “Regular Expression” mode an “☑ . matches newline” checkbox.

      Specifically:

      • FIND = "items": \\[.*?\\]
        REPLACE = "items": []

      2a11071a-2b50-41bb-932b-7cfe502b39d5-image.png

      You need to use \\[ instead of just [ in the FIND expression, because [ has special meaning to regex, and the \ prefix tells the regex to look for the literal opening square bracket, not treat it as the special regex character

      ----

      Useful References

      • Please Read Before Posting
      • Template for Search/Replace Questions
      • Formatting Forum Posts
      • Notepad++ Online User Manual: Searching/Regex
      • FAQ: Where to find other regular expressions (regex) documentation
      1 Reply Last reply Reply Quote 4
      1 out of 2
      • First post
        1/2
        Last post
      The Community of users of the Notepad++ text editor.
      Powered by NodeBB | Contributors