This question already has answers here:
Using regex to add leading zeroes
(13 answers)
Closed 5 years ago.
Question - what is the shortest form of regex to add a leading zero into a found pattern?
I want to add a leading zero to any number that matches this regex pattern
[(][0-9][0-9][0-9][0-9][-][0-9][0-9][0-9][0-9][-][0-9][0-9][)]
I am using Notepad++.
In Notepad++ Regex Replace, you use $n to represent the nth capture group for replacement:
Search for: [(]([0-9][0-9][0-9][0-9][-][0-9][0-9][0-9][0-9][-][0-9][0-9])[)]
Replace with: (0$1)
Related
This question already has answers here:
What is a word boundary in regex?
(13 answers)
Difference between \b and \B in regex
(10 answers)
Regex using word boundary but word ends with a . (period)
(4 answers)
Closed 3 months ago.
I am trying to match an exact word with multiple patterns using regex.
What I tried:
pattern: "\b(#DOG|#DOG1|#DOG2)\b", text: "#DOG2".
I want to match exact text "#DOG2" using these patterns, and the expected result should be: there is only 1 match "#DOG2". How can I change the pattern text to achieve this?
Interestingly, if I remove all '#' symbol from above text, the regex will work as expected:
pattern: "\b(DOG|DOG1|DOG2)\b", text: "DOG2".
Does '#' affect the result? How can I avoid this?
This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 2 years ago.
I am currently using the following character class:
[^\)\(] in my regex
I want to add the word 'hello' to this class so it is also not matched in my string.
I have tried
[^\)\((hello)]
but it does not work.
What can I do?
One typical way you would enforce that hello does not appear would be to use a negative lookahead, e.g.
^(?!.*hello)[^t()]+$
If you only wanted to exclude hello when it appears as a bona fide word, then surround it with word boundaries in the lookahead:
^(?!.*\bhello\b)[^t()]+$
This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 5 years ago.
I would like to find dots/punctuations not surrounded by any numerics or alphanumerics (in other words surrounded by nothing) and replace these with nothing using Notepad++ and regex.
I tried using
(?<![a-zA-Z0-9]).(?![a-zA-Z0-9])
but it replaces all the numbers surrounding each dot with nothing.
How can this expression be adjusted appropiately for use in Notepad++ ?
You need to escape the . character:
(?<![a-zA-Z0-9])\.(?![a-zA-Z0-9])
This question already has answers here:
Regex match entire words only
(7 answers)
Closed 7 years ago.
var text = 'word otherword';
I want to select words that only matches with 'word'. When i use simply /word/ for regex pattern, then it also selects the 'word' part in 'otherword'. I dont need that word(in this case 'otherword').So how can i only select/match 'word' word using regex?
Use word boundary - \b.
/\bword\b/
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Regular expression to match string not containing a word?
How can I invert a regular expression in JavaScript?
Say I have the regex foo123. How do I match everything that is not foo123?
Use negative lookahead for this.
(?!foo123).+
matches any string except foo123
If you want to match empty string also, use (?!foo123).*
In your case (according to the comment) the required regex is (?!P[0-9]{1,}).+.
It matches P and 123, but not P123.