^([\\w\\-]+)
can find the first word but it stops the sub string at a . or _. I only want it to stop at the first space.
You may use \\S+
to match one or more non-space characters. So the regeex must be,
^\S+
Example:
> 'foo.+() bar'.match(/^\S+/)[0]
'foo.+()'
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.