Find and replace everything between and including parentheses



  • 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



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



  • 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


Log in to reply