[英]How can I extract all the words after a symbol and before space by Regular Expression
For instance, how can I extract '@dog @cat' from 'rabbit @dog bird @cat fish' by regular expression? 例如,如何通过正则表达式从“兔子@狗鸟@猫鱼”中提取“ @dog @猫”?
Thanks a lot! 非常感谢!
You can use following regular expression (Using \\w
to match alpha-numeric/underscore character): 您可以使用以下正则表达式(使用
\\w
匹配字母数字/下划线字符):
@\w+
Javascript example: JavaScript示例:
'rabbit @dog bird @cat fish'.match(/@\w+/g)
// => ["@dog", "@cat"]
Try this regex :: 试试这个正则表达式::
/@(dog|cat)\b/
Demo: https://regex101.com/r/yO2cZ0/1 演示: https : //regex101.com/r/yO2cZ0/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.