使用Java,我想提取美元符号之间的单词$
.
例如:
String = " this is first attribute $color$. this is the second attribute $size$"
我想拔出绳子:color
and size
并将它们放入列表中。
我努力了:
Pattern pattern = Pattern.compile("(\\$) .* (\\$)");
Matcher matcher = pattern.matcher(sentence);
但我得到输出:
"$color$.this is the second attribute $size$"
做这个的最好方式是什么?
问题在于.*
火柴any象征。所以你的模式结果是正确的,因为开头和结尾都是美元符号。
如果美元之间的变量只是字母数字使用\$\w+\$
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)