Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for match all words without numbers

Tags:

regex

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..

like image 304
ROZZ Avatar asked Mar 31 '15 18:03

ROZZ


People also ask

What does ?= Mean in regex?

?= 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).

Does empty regex match everything?

An empty regular expression matches everything.

What does \b mean in regular expressions?

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”.

Which regex matches the whole words dog or cat?

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.


1 Answers

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.

like image 136
anubhava Avatar answered Sep 28 '22 10:09

anubhava