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/
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:
Regex: ignore case sensitivity
(15 answers)
Closed 2 years ago.
Any ideas why this regex doesn't match everything from my string? (I want it to match discord.gg/XUGswJ)
[a-z] means lowercase letters. You probably want [a-zA-Z] to include uppercase.
This question already has answers here:
Regex: matching up to the first occurrence of a character
(14 answers)
Closed 4 years ago.
can someone please quickly help me with regularexpression to match any character and group it which is coming behind front shash:
ae-app001/UK/Server/company
in this i want to match ae-app001 only.
the format remains the same except that we dont know how many slash might be there,
sometimes the string might be just :
ae-app001/UK/Server
so i need a generic regex which will match string1 in the below:
string1/string2/string3/string4
string1/string2/string3
etc..
/^([^\/]+)/ Demo
But what if there's no slashes? Is it ok to capture whole string?
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)