I want to find a text with with digit followed by a dot and replace it with the same text (digit with dot) and "xyz" string. For ex.
1. This is a sample
2. test
3. string
**I want to change it to**
1.xyz This is a sample
2.xyz test
3.xyz string
I learnt how to find the matching text (\d.) but the challenge is to find the replace with text. I'm using notepad ++ editor for this, can anyone suggest the "Replace with" string.
in regex is a metacharacter, it is used to match any character. To match a literal dot in a raw Python string ( r"" or r'' ), you need to escape it, so r"\." Unless the regular expression is stored inside a regular python string, in which case you need to use a double \ ( \\ ) instead.
The period (.) represents the wildcard character. Any character (except for the newline character) will be matched by a period in a regular expression; when you literally want a period in a regular expression you need to precede it with a backslash.
The 0-9 indicates characters 0 through 9, the comma , indicates comma, and the semicolon indicates a ; . The closing ] indicates the end of the character set. The plus + indicates that one or more of the "previous item" must be present.
If you're looking for a space, that would be " " (one space). If you're looking for one or more, it's " *" (that's two spaces and an asterisk) or " +" (one space and a plus).
First of all, you need to escape the dot since it means "match anything (except newline depending if the s
modifier is set)": (\d\.)
.
Second, you need to add a quantifier in case you have a 2 digit number or more: (\d+\.)
.
Third, we don't need group 1 in this case: \d+\.
.
In the replacement, it's quite simple: just use $0xyz
. $0
will refer to group 0 which is the whole match.
For notepad++...
You must escape the period/dot character in the expression - precede it with a backslash:
\.
In my case, I needed to find all instances of "{EnvironmentName}.api.mycompany.com" (dev.api.mycompany.com, stage.api.mycompany.com, prod.api.mycompany, etc.) I used this search expression:
.*\.api.mycompany.com
Notepad++ RegEx Search Screenshot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With