Reputation: 4390
I require a Regular Expression to match single words of [a-zA-Z] only with 6 or more characters.
a
27
it was good because
it
cat went to
four
eight is bigger
peter
pepper
objects
83
harrison99
adjetives
atom-bomb
pepper
objects
adjectives
it was good because
eight is bigger
atom-bomb
/[a-zA-z]{6,}/g
Which matches 6 character or more words according to RegEx 101 but when I use it in my MySQL database to filter a table on matches RegExp.
If a row contains a number or punctuation and/or contain one or more words I don't want it included.
I want only results that are single, whole words of 6+ characters
Upvotes: 1
Views: 725
Reputation: 12389
Drop the delimiters and add anchors for start/end:
SELECT 'abcdef' REGEXP '^[a-zA-Z]{6,}$'
-> 1
SELECT 'a abcdef' REGEXP '^[a-zA-Z]{6,}$'
-> 0
Also I changed [a-zA-z]
in the character class to [a-zA-Z]
.
Instead of [a-zA-Z]
you can also use [[:alpha:]]
POSIX style bracket extension. So it becomes:
^[[:alpha:]]{6,}$
(As a side note: MySql uses Henry Spencer's implementation of regular expressions. if word boundaries needed, use [[:<:]]word[[:>:]]
See manual for further syntax differences)
Upvotes: 3