简体   繁体   English

如何通过正则表达式提取符号之后和空格之前的所有单词

[英]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.

相关问题 如何通过匹配正则表达式提取所有子字符串? - How can I extract all substring by matching a regular expression? 正则表达式在斜杠前提取单词 - Regular expression to extract words before a slash 如何使用正则表达式提取驼峰式字符串的所有单词? - How to extract all words of a camel cased string with a regular expression? 如何将正则表达式中的单词列入黑名单? - How can i blacklist words in a regular expression? 正则表达式以提取“ ||”符号之间和之后的文本 - Regular expression to extract text between and after “||” symbol 正则表达式提取所有以冒号开头的单词 - Regular expression to extract all words starting with colon 正则表达式:符号之前或之后的模式 - regular expression: a pattern either before or after a symbol 如何使用JavaScript正则表达式匹配包含两个相同单词的字符串中的单词? - How can i match a word in a string which has two same words before it using JavaScript regular expression? 原始字符串包含“ +”,正则表达式提取器(。+?)将其替换为空格。 我如何用“ +”提取 - Original string contains “+”, regular expression extractor (.+?) replaces it with a space. How can I extract with the “+” PHP正则表达式空间或换行符之前或之后 - PHP regular expression space or newline before or after
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM