I am using following regex to find out to detect atleast one character.
/\b([a-zA-Z0-9_]{1,})$/
Right now I need to detect space also.
How can I do that?
You can detect space in Regex by using \\s
. This token will catch any space in the string. In your regex, You can include this token \\s
inside the brackets []
.
Your regex has also a-zA-Z0-9_
to catch any number, uppercase letters, lower case letters, or underscore _
. All of these can be caught using one single token that is designed to catch such characters which is \\w
. This is optional, but it will help shorten your Regex to make the tokens between brackets only [\\s\\w]
.
Your Regex can be:
/\b([\s\w]{1,})$/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.