0

I would like a regular expression that matches this: word,"number",word

Where number is something like: 100,000.00

So far I have this but I'm not sure how to check for quotes around a number.

(w+)(,)\\(d+)(,)(d+)(.)(d+)(,)\\(w+)(,)
4

2 回答 2

1

只需添加带有转义字符的引号,如下所示:

\\w+,\\"\\d+,\\d+\\.\\d+\\",\\w+

我删除了最后一个昏迷......因为不是模式的一部分。

于 2012-10-24T00:10:37.100 回答
0

如果您的号码后面可以有很少(或没有)分号和树数字,或者精度部分可以是可选的,您可以使用这个正则表达式:

String regex=
        "\\w+,\"" +     // word, semicolon, quote mark
        "\\d{1,3}" +    // number in form d, dd, or ddd
        "(,\\d{3})*" +  // optional (* means 0 or more times) part of numbers in format ",ddd"  
        "(\\.\\d{2})?" +// optional (? means 0 or 1 time) part ".dd" 
        "\",\\w+";      // quote mark, semicolon, word

这将接受:

-precision part is optional
d
d.dd 

-number of semicolons can change, but every semicolon MUST have 3 digits after it
dd,ddd
d,ddd,ddd
d,ddd,ddd.dd
于 2012-10-24T01:09:36.973 回答