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..
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..
You can use this regex:
/\b[^\d\W]+\b/g
to match all words with no digits.
[^\d\W] will match any non-digit and (non-non-word) i.e. a word character.
If the task is to match words that only consist of letters, you can use the following solutions:
r'\b[^\W\d_]+\b' (see demo)/\b\p{Alphabetic}+\b/gu (see demo) NOTE: requires ECMAScript 2018+ support.'~\b\p{L}+\b~u' (see demo)/\b\p{L}+\b/ (see demo)@"\b\p{L}+\b" (see demo)"\b\p{L}+\b" (see demo) R"(\b[[:alpha:]]+\b)" (see demo) NOTE: Only ASCII letters are considered word chars."(*UCP)\\b\\p{L}+\\b" for base R function with perl=TRUE (see demo) or just "\\b\\p{L}+\\b" for stringr regex functions"%f[%a]%a+%f[%A]" (see demo)NOTE: Only ASCII letters are considered word chars.sed -E 's/\b[[:alpha:]]+\b/DELETED/g' file (see demo)grep -oE '\b[[:alpha:]]+\b' file (see demo)set pattern {\y[[:alpha:]]+\y} (see demo)Note that most PCRE-based or PCRE-originated regex flavors use \b to match leading/trailing word boundaries. PostgreSQL and Tcl use \y instead of \b. There are other types of word boundaries, like \m (Tcl, PostgreSQL), or \< (Vim, GNU sed or grep, base R), or [[:<:]] (MacOS FreeBSD grep/sed, MySQL up tp v6, base R with perl=TRUE, PCRE in general) to match a leading word boundary and \M, or \>, or [[:>:]] accordingly to match closing, or trailing, word boundary.
This expression worked for me:
/[a-zA-Z]+'?[a-zA-Z]+/g
Not only it matches all the words and ignores the numbers, it also gets words like "he's", "we're", "what's", "Bruce's".