basically im trying to create a regex pattern that get every word that starts with an @
For example :
@Server1:IP:Name Just a few words more
the pattern should find "@Server1:IP:Name"
Ive created a regex pattern that worked so far :
/@\w+/
The problem is everything after a colon wont get matched anymore. If i use this regex i get this as a result for example :
@Server1
how do i make sure it will get the entire word starting with an @ and ignoring colons in it?
it is works fine try it:
@\w\S+
\\w matches any word character (equal to [a-zA-Z0-9_])
matches any non-whitespace character
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
You can use this
@[\w\s:]+
If your string contains any (!@#$%^&*()_+.) you could add them too.
try this @\\S+
It gives you everything between "@" and the next space.
\\S
matches any non-whitespace character.
refer this
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.