I have this string:
" abalbal asldad 23 sadaskld 3123 adasdas "
How to match only the words, without numbers.. with " \D* "
I can match only the first two, without others..
?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured. Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).
An empty regular expression matches everything.
Simply put: \b allows you to perform a “whole words only” search using a regular expression in the form of \bword\b. A “word character” is a character that can be used to form words. All characters that are not “word characters” are “non-word characters”.
If we want to improve the first example to match whole words only, we would need to use \b(cat|dog)\b. This tells the regex engine to find a word boundary, then either cat or dog, and then another word boundary.
You can use this regex:
/\b[^\d\W]+\b/g
to match all words with no digits.
RegEx Demo
[^\d\W]
will match any non-digit and (non-non-word) i.e. a word character.
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