示例输入将是;
$500 has been received from username.
到目前为止,我有这个正则表达式字符串;
$ \\$(\\d+\\.?\\d*) has been received from
这应该提取余额(如果我是正确的?)问题是,我想不出如何获得用户名的解决方案。用户名字符串是字母数字,因此不能包含fullstops。在'直到''之后我会用什么来获取所有角色?'?
谢谢!
答案 0 :(得分:1)
根据这个网站:
http://www.regexplanet.com/advanced/java/index.html
这应该有效:
^\$(\d+\.?\d*) has been received from (.*).$
答案 1 :(得分:0)
([^.]+)
捕获所有内容,直到找到一个点。
^\$(\d+\.?\d*) has been received from ([^.]+)\.$
反斜杠的原因是直接跟随在正则表达式语言中使用特殊字符。
在Java中使用时,它看起来像这样:
"^\\$(\\d+\\.?\\d*) has been received from ([^.]+)\\.$"
这里需要额外的反斜杠,因为在Java字符串中,反斜杠本身是一个特殊的字符,必须进行转义。