简体   繁体   中英

Java Regex Matcher matches . (dot) even if it is not in Pattern

I want to parse semicolon separated string, that has or has not semicolon at the end

I have Regex Pattern (\\s*\\w+)(\\s*;)* which I interpret as to match:

0..n spaces followed by 1..n characters followed by 0..n spaces that end with semicolon.

My problem is that I get "wrong match" if there is a '.' in input string Example:

0000.274283;518600.00-F10W;

Instead of expected '0000.274283;' I get '0000'.

What am I missing?

\\w matches any word character. So you are matching 0-n spaces followed by 1 or more letter, number, or underscore. Since '.' is not included, your regex will not match strings with a '.' in it, hence why you only get 0000 instead of 0000.274283

[^;]+匹配除分号之外的所有内容,因此也许您可以使用此字符将您给定的字符串用分号分隔。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM