正则表达式匹配以 $ 开头的整个单词 [英] Regex to match whole words that begin with $

查看:90
本文介绍了正则表达式匹配以 $ 开头的整个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个正则表达式来匹配以 $ 开头的整个单词.表达式是什么,如何测试?

I need a regex to match whole words that begin with $. What is the expression, and how can it be tested?

示例:

这个 $word 和 $this 应该被提取出来.

This $word and $this should be extracted.

在上面的句子中,会找到$word$this.

In the above sentence, $word and $this would be found.

推荐答案

如果只想匹配整个单词,则需要单词字符选择器

If you want to match only whole words, you need the word character selector

\B\$\w+

这将匹配 $ 后跟一个或多个字母、数字或下划线.在 Rubular 上试用

This will match a $ followed by one or more letters, numbers or underscore. Try it out on Rubular

这篇关于正则表达式匹配以 $ 开头的整个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆