This is the line:
I love you and George loves IOANA but also Mihai is my enemy.
I want to match 2 words before IOANA, and also 2 words after IOANA
The Output should be:
I love you and IOANA Mihai is my enemy.
I believe my regex must be upgrade a little bit, as to work:
SEARCH: (^.*)(?s)(\w+{2}IOANA\w+{2})(.*)
REPLACE BY: \1\2
1 Answer
- Ctrl+H
- Find what:
(?:\S+ ){2}(IOANA)(?: \S+){2} - Replace with:
$1 - CHECK Match case
- CHECK Wrap around
- CHECK Regular expression
- UNCHECK
. matches newline - Replace all
Explanation:
(?: # non capture group \S+ # 1 or more non space character # a space
){2} # end group, must appear twice
(IOANA) # group 1
(?: # non capture group # a space \S+ # 1 or more non space character
){2} # end group, must appear twiceI guess, here, that you means words are composed with non spaces characters.
- If, for you, word contains only letters and digits, use
[a-zA-Z0-9]+instead of\S+. - If, for you, word contains only letters and soeme punctuation like
', use[a-zA-Z']+instead of\S+.
Screenshot (before):
Screenshot (after):
1