Answer the question
In order to leave comments, you need to log in
RegEx for words of letters _And_ numbers
Tell me, is it possible to check with one expression whether a word consists of letters and numbers. The conditions are as follows:
* Characters can be placed in any order (it can start / end with a letter or number)
* The word consists of Latin letters and numbers
* The word does NOT consist of letters only
* The word does NOT consist of numbers only
Answer the question
In order to leave comments, you need to log in
Why not? Can. When writing regexps, you need to operate not with logical conditions, but with the order of characters in a string. Your string looks like this:
((one or more letters, then one or more digits) or (one or more digits, then one or more letters)) then optionally letters or digits
Here is the regression:
(([az]+\d+) |(\d+[az]+))[az\d]*
regexr.com?33fas
One is unlikely. And why? Do you need it to work, or do you need it to be cool? :)
You need three checks - that there are only letters + numbers, that there are letters, that there are numbers.
/^[a-z0-9]+$/ && /[a-z]/ && /[0-9]/
Fail regexr.com?33gal
oops should have come here habrahabr.ru/qa/32825/#answer_128961
Perhaps so.
\b(\d+\w+)\b|\b(\w+\d+)\b|\b(\d+\w+\d+)\b|\b(\w+\d+\w+)\b
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question