This question already has answers here:
Notepad++ and regex: how to UPPERCASE specific part of a string / find / replace
(2 answers)
Closed 4 years ago.
In notepad++ I need to use RegEx transform all
phone1_id, phone2_id, phone3_id
in
PHONE1_ID, PHONE2_ID, PHONE3_ID
This RegEx helps me find all those strings: phone\d+_id
but how can I transform them to capital case?
Ctrl+H
Find what: phone\d+_id
Replace with: \U$0
check Wrap around
check Regular expression
Replace all
Replacement:
\U : Change to uppercase
$0 : contains the whole match
Result for given example:
PHONE1_ID, PHONE2_ID, PHONE3_ID
Related
This question already has answers here:
What is the difference between .*? and .* regular expressions?
(3 answers)
What do 'lazy' and 'greedy' mean in the context of regular expressions?
(13 answers)
Closed 5 months ago.
There is a line of text:
Lorem ~Ipsum~ is simply ~dummy~ text ~of~ the printing...
To find all the words enclosed in ~~ I use
re.search(r'~([^~]*)~', text)
Let's say it became necessary to use ~~ instead of ~
([^\~]+) indicates to exclude the ~ character from the text within those characters
How do I make a regular expression to exclude a string of characters instead of just one?
That is, ~~Lor~em~~ should return Lor~em
The symbol of the new string must not be excluded and the length of the found string cannot be 0
Use a non-greedy quantifier instead of a negated character set.
re.search(r'~~(.*?)~~', text, flags=re.DOTALL)
re.DOTALL makes . match newline characters.
This question already has answers here:
Regular Expression, remove everything after last forward slash
(5 answers)
Closed 3 years ago.
I am trying to get the syntax right so that I can make scanning-client-container-0.2.tar look like scanning-client-container
I am using the delimiter " - " like so:
sed -e 's/-[^*]*$//'
with the result scanning, which is cut off too early
You can use a negated character class in your regex:
sed 's/-[^-]*$//' <<< 'scanning-client-container-0.2.tar'
scanning-client-container
RegEx Details:
-: Match a -
[^-]*: Match 0 or more characters that are not -
$: Match end
This question already has answers here:
How can I make my match non greedy in vim?
(8 answers)
Closed 4 years ago.
I'we been trying to do simple substitution in vim, and find out that the \? in vim not works with * or +, saying that (NFA regexp) Can't have a multi follow a multi, in the vim:
i want it to stop here, not here
~
~
~
[NORMAL] ...
:%s/^\(.*\?\)here//
If I remove \? it works, but the it regex matches up to 2nd here.
But with normal regex it works: https://regex101.com/r/iHdxxl/1
Why it isn't possible to use \? with * or \+ in vim?
As stated there, you can't add the ? char in vim after the asterisk.
To make the search non greedy, you need to use .\{-} instead of .*:
:%s/\(.\{-}\)here//
Another option is to use negative lookahead:
:%s/\v^((here)#!.)* here//
\v is used for very magic to avoid escaping all over in regex.
This question already has answers here:
Notepad++ Regex - Issue with ^ anchor and repeating patterns
(2 answers)
Closed 5 years ago.
To remove, e.g. (exactly) 2 leading spaces from each line, I've tried to replace
"^ "
with
""
I tried that with our own text editor and with Notepad++. Both behave the same and start the search at the same position where the last found/replace happend, so it will actually remove 2n spaces from each line (n >= 0). Is this the expected behavior? Is my used regular expression wrong for that task or do our own text editor and Notepad++ behave incorrectly?
The issue here is that Notepad++ will keep replacing a pattern so long as it keeps finding matches. This means that replacing ^ will keep stripping whitespace from the start of the string, so long as there are two or more leading spaces available.
Try this as a workaround:
Find:
^ (.*)$
Replace:
$1
This question already has answers here:
replacing word after multiple spaces
(6 answers)
Closed 9 years ago.
I have a problem. I want to get the word trust from this sentence and replace it with md5 using RegEx:
host all all 127.0.0.1/32 trust
Find : ^((?:\S+\s+){4})\S+
replace by : ${1}md5
For example, in Perl, i'd do:
my $str = 'host all all 127.0.0.1/32 trust';
$str =~ s/^((?:\S+\s+){4})\S+/${1}md5/;
This regex captures the fifth word: ^.+\s+.+\s+.+\s+.+\s+([^\s]+)\*\* and requires that two asterisks came after the word (and the asterisks are not captured)
You can also have a look at this regex:
^(?:.+?\s+){4}(\b.+?\b)
Replace using this regex to md5 will do the job