Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Find and replace everything between and including parentheses

    General Discussion
    2
    3
    866
    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.
    • haitt2102
      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
      • haitt2102
        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
        • guy038
          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
          Copyright © 2014 NodeBB Forums | Contributors