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?
Related
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:
regex: required character in brackets
(3 answers)
Closed 4 years ago.
I am working for something and writing a regular expression to capture a string which is either (numbers and letters) or only numbers.
I know a regex for only number is [0-9] and alphanumeric is [A-Za-z0-9] . But this would capture even the strings which are only letters. How do i force it to not have only letters? Is there a way to do it in a single regex?
([0-9]*[a-zA-Z]*[0-9])+([a-zA-Z]*)
This should solve your problem.
You can test it here
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:
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)
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/