Community
    • Login

    Find and replace everything between and including parentheses

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 1.1k 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.
    • haitt2102H
      haitt2102
      last edited by

      I have a txt file
      Example:
      STR-405384
      Getting the hang of this now![COMMENT Addictedness string]

      STR-442968
      Run At Defence[COMMENT - high dribbling tactic]

      STR-443001
      The current squad tends to fear playing in big matches[COMMENT
      Team report traits; keep short]
      STR-443002
      We have a calm và amicable group of players[COMMENT
      Team report traits; keep short]

      I want the result is
      STR-405384
      Getting the hang of this now!

      STR-442968
      Run At Defence
      STR-443001
      The current squad tends to fear playing in big matches
      STR-443002
      We have a calm và amicable group of players

      1 Reply Last reply Reply Quote 0
      • haitt2102H
        haitt2102
        last edited by

        I used
        Find what:\[COMMENT .*?\]
        and check the regular expression
        But resuilt is no exactly

        1 Reply Last reply Reply Quote 0
        • guy038G
          guy038
          last edited by

          Hello @haitt2102, and All,

          Your regex is quite correct but ONLY IF the [COMMENT.....] area of chars belongs to an unique line, as in the first two occurrences of your example !

          So, you must use the (?s) modifier syntax to be sure that the dot regex meta-charaqcter match any single char ( standard or EOL chars ) in order that a match may be spread out on several lines !

          Thus, this regex S/R should work :

          SEARCH (?s)\[.+?\]

          REPLACE Leave EMPTY

          If your text may also content square bracket(s) as normal characters, the regex, below, will be more restrictive :

          SEARCH (?s-i)\[COMMENT.+?\]

          Note that I added the (?-i) modifier ( meaning no-insensitive ), to be sure that the regex engine will search for the uppercase string COMMENT

          Remarks :

          • The (?s) or (?-s) has higher priority than the . matches newline option of the Find/Replace dialog. Idem for the (?i) or (?-i) modifiers, regarding the Match case option

          • Notice, also, that the (?s)\[.+?\] regex, could be replaced with the \[(.|\R)+?\] regex, which matches exactly the same occurrences, as \R match any kind of new-line characters !

          Cheers,

          guy038

          1 Reply Last reply Reply Quote 2
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors