Notepad ++ wildcards on dialogue - replace

how to find and replace all characters with empty after Adam: name using a wild card in notepd++?
For example, I have the following 4 rows:
Eva: hi how are you
Adam: I'm fine thank you, and you?
Eva: well, I am cooking dinner, I am fine
Adam: excellent what are you cooking?
I want to have the following 4 rows to isolate Eva dialogue lines:
Eva: hi how are you
Eva: well, I am cooking dinner, I am fine
thank you, Sid

Ctrl+H
Find what: ^Adam:.+$
Replace with: LEAVE EMPTY
CHECK Match case
CHECK Wrap around
CHECK Regular expression
UNCHECK . matches newline
Replace all
Explanation:
^ # beginning of line
Adam: # literally
.+ # 1 or more any character but newline
$ # end of line
Screenshot (before):
Screenshot (after):

Related

Using Regex selecting text match everything after a word or patterns (similar topic but text is not fix patterns except 1 character)

I am trying to use Regex in notepad++ to select everything after v+(number|character)* but in the selection it should excluded the v+(num|char)*.
e.g. master\_\move_consolidate_archives_html_to_move_base_v2kjkj_(2021_01_19_11h43m59s-fi_m_dt xx-) - Copy (2).bat"
I am expecting
_(2021_01_19_11h43m59s-fi_m_dt xx-) - Copy (2).bat"
so far I can use this line (?i)(v\d[0-9a-z]*)
to select v2kjkj
but I can't get this to work with lookbehind (?<=xxxx).
I am also trying to use if-then-else condition but no luck for me. I am still don't understand enough to using it.
issue.
because the "v" have different pattern in it. I can't hard code to certain string
v2
v23
v2kjkj
v2343434
Test string:
mmaster\_\move_consolidate_archives_html_to_move_base_v2_16_.bat"
master\_\move_consolidate_archiv es_html_to_move_base_v23_17_.bat"
master\_\move_consolidate_archives_html_to_move_base_v2_17_(2021_01_19_12h37m19s-fi_m_dt xx-).bat"
master\_\move_consolidate_archives_html_to_move_base_v2_(2021_01_19_11h43m59s-fi_m_dt xx-) - CopyCopy.bat"
master\_\move_consolidate_archives_html_to_move_base_v2kjkj_(2021_01_19_11h43m59s-fi_m_dt xx-) - Copy (2).bat"
master\_\move_consolidate_archives_html_to_move_base_v2343434_(2021_01_19_11h43m59s-fi_m_dt xx-) - Copy (3).bat"
I have been reading and searching for a day but I can't apply anything I have seen so for.
the closest one I see was
Regexp match everything after a word
Getting the text that follows after the regex match
I am welcome any comments.
Ctrl+H
Find what: v\d[0-9a-z]*\K.*$
Replace with: LEAVE EMPTY
UNCHECK Match case
CHECK Wrap around
CHECK Regular expression
UNCHECK . matches newline
Replace all
Explanation:
v # a "v"
\d # a digit
[0-9a-z]* # 0 or more alphanum
\K # forget all we have seen until this position
.* # 0 or more any character but newline
$ # end of line
Screenshot (before):
Screenshot (after):

Notepad ++ regex. Finding and replacing with wildcard, but without allowing any spaces?

I have something like this in txt
[[asdfg]] [[abcd|qwerty]]
in a row, but I want it to look like that
[[asdfg]] [[qwerty]]
using wildcards ( [[.*\| ) when trying to search, results in it finding the whole line up to the "|" Not allowing it to have a space in between should work, but I don't know how to do that.
Edit 1
It's from a wikipedia dump, so the first part is the word in it's basic form and the second is how it fits into the sentence. Something like [[I]] [[be|was]] [[at]] [[the]] [[doctor]] And I want to change it into normal sentences
[[I]] [[was]] [[at]] [[the]] [[doctor]]
Edit 2
I found somewhat of a solution. I just put every word in a new line, did the first regex and then deleted newlines. That did kinda mess up my spacing though...
Try this regex:
\[\[\w+\|(\w+)\]\]
Replace with:
[[$1]]
Make sure you choose Regular expression at the bottom before you click Replace All in Notepad++.
You can do it all in one run like so
\[{2}(?:(?!\]{2}).)+?\|([^\]]+)
This needs to be replaced by
[[$1
See a demo on regex101.com.
Broken down this says:
\[{2} # match [[
(?:(?!\]{2}).)+? # do not overrun ]]
\| # |
([^\]]+) # capture anything not ] into group 1
Afterwards, you'll only need to replace the open brackets and the content of group $1

regular expression - comment out all lines containing the word "logging"

I am trying to mass comment out all the lines referring to logging in a code.
I am using notepad ++ and ideally this would be achievable by replacing all the lines being like
< some text > logging
by
# < some text > logging
Sorry in advance to ask this kind of question on SO, but I'm kind of stuck , and I'm sure this can be useful to other people.
In notepad++,
Search "^(.*) logging"
Replace "#\1 logging"
Make sure search mode is "Regular expression"
Find with (?=.*logging)^ and replace with #
Eplanation:
(?=.*logging) will lookahead for word logging and if present search for beginning of string with ^
Regex101 Demo
Find what : ^.*logging$
Replace with: # $0
Search mode: Regular expression
$0 is a variable for the match.
And the regex matches a line that ends with "logging".
So replacing it with # $0 puts a # at the start of a line that ends with logging.
^ : start of a line
.* : zero or more characters
$ : end of a line
And to a avoid commenting lines that are already are commented?
Adding a negative lookahead helps with that:
Find what: ^(?!\s*#).*logging$

replace after "word" character by character in notepad ++?

I have a STRING
"wordride plain fire "
I have tried to replace with Regular Expressions:
Find what: (?>(word)|\G(?<!^))\K\S
Replace with: $1$2$0
In Notepad ++, it does not change the text but it works in regex101 (https://regex101.com/r/aI6gE1/2), where i replaces characters after word as follows
First replace: wordwordide plain fire
Second replace: wordwordwordde plain fire
Third replace: wordwordwordworde plain fire
Fourth replace: wordwordwordwordword plain fire
Fifth replace: wordwordwordwordwordwordplain fire
Sixth replace: wordwordwordwordwordwordwordlain fire
Can you help me to see the error or give me a workaround in Notepad ++ for this purpose: replacing string after "word" character by character using a group not included in match group
Please help me
The answer is yes, it is possible to do with Notepad++ BUT only with the help of a PythonScript plug-in.
Get the plugin ready, and create the following script:
import re
regex = r"^(word)(.+)"
def process_match(match):
return "{0}{1}".format(match.group(1), "".join([match.group(1) for x in list(match.group(2))]))
editor.rereplace(regex, process_match)
The ^(word)(.+) pattern will match a line with word at its start into Group 1 and all the rest of the line into Group 2.
The "{0}{1}".format(match.group(1), "".join([match.group(1) for x in list(match.group(2))])) will paste the Group 1 value into the result first (see format(match.group(1)) and then "".join([match.group(1) for x in list(match.group(2))]) will replace each character in Group 2 with the value in Group 1.
This text:
word1
word1 2
wordride plain fire
will turn into:
NOTE: You can control how many chars after word are replace with word by adjusting (modifying) the (.+) pattern.
It's hard to understand exactly what you want to do but the following is working based on your examples:
Find: ^((word)+).
Replace with: $1$2

Regex to add part of string to end of line in my Text Editor

I'm using Sublime 2 Text Editor which accepts RegEx search and replace. I'm attempting to find a whole line, then replace that whole line with a string found in the line itself.
This is my text that I am searching:
strEventID = CheckForNull(reader("
strEventKey = CheckForNull(reader("
strEventTitle = CheckForNull(reader("
I want to this text to become:
strEventID = CheckForNull(reader("EventID"))
strEventKey = CheckForNull(reader("EventKey"))
strEventTitle = CheckForNull(reader("EventTitle"))
I know that FIND: (^.*$) will match the whole line and I can REPLACE with $1 and add to that line manually, but I can't figure out how to add part of the string back in.
Update:
(str(\w*).*)$
replace with $1$2")) or $1$2"\)\) here in notepad++.
Make sure the ". matches newline" is unchecked
old answer:
Try:
^(str(.*\b).*)$
replace with $1$2")).
I don't have sublimeText with me right now, but this test http://regex101.com/r/hM2oX2/1 says group 1 is the whole line, and group 2 is your first match. concatenate...
In Sublime, you can use the following regular expression: \K resets the starting point of the reported match and any previously consumed characters are no longer included.
Find What: str(\w+).*\K
Replace With: $1"))