I want use \w
regex for to allow alpha numeric but I don't want underscore _
to be part of it. Since _
is included in \w
. So I have coded like this but doesn't work, what is my mistake?
(/^roger\w{2,3}[0-9a-z]/i)
I am expecting any character other than A-Z or 1-2 to be exclude
ex -
roger3_2 or roger46_ or roger2_
but
roger54 or roger4a or roger455 or rogerAAA
are to be ok
A domain name may include lowercase and uppercase letters, numbers, period signs and dashes, but no underscores. \w includes all of the above, plus an underscore.
\W matches any character that's not a letter, digit, or underscore. It prevents the regex from matching characters before or after the phrase.
Regex doesn't recognize underscore as special character.
A regular expression for an alphanumeric string checks that the string contains lowercase letters a-z , uppercase letters A-Z , and numbers 0-9 .
You could try something like:
[^_\W]+
\pN
or \p{Number}
.\d
, \p{digit}
, \p{Nd}
, \p{Decimal_Number}
, or \p{Numeric_Type=Decimal}
.\p{alpha}
or \p{Alphabetic}
. It includes all \p{Digit}
, \p{Letter}
, and \p{Letter_Number}
code points, as well as certain \p{Mark}
and \p{Symbol}
code points.\w
, or [\p{Alphabetic}\p{Digit}\p{Mark}\p{Connector_Punctuation}]
.An alphanumeric code point by the strictest definition is consequently and necessarily [\p{Alphabetic}\p{Number}]
, typically abbreviated [\p{alpha}\pN]
.
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