简体   繁体   中英

coordinate regex not match if value more than 99

I have a regex like this :

(-?\d{1,2}\.\dE-\d+|-?\d{1,2}\.?\d*)\s(-?\d{1,2}\.\dE-\d+|-?\d{1,2}\.?\d*)\s?0?\s?0?,?

and i test with

99.972534 -6.147714,

that's match all of the test. but when i use

100.972534 -6.147714,

all match but '1' of 100, the result like this :

00.972534 -6.147714,

please help me update this regex so can match the test

thanks

(-?\d{1,2}\.\dE-\d+|-?\d{1,3}\.?\d*)\s(-?\d{1,2}\.\dE-\d+|-?\d{1,2}\.?\d*)\s?0?\s?0?,?
                           ^

Try this.See demo.It was accepting only 2 digits.Made it to accept 3 .

http://regex101.com/r/hQ9xT1/30

Your regex specifies 1 or 2 leading digits via \\d{1,2} , but 100 has 3 digits.

Change all occurrences of \\d{1,2} to \\d{1,3}

At the beginning of your regex, you have "\\d{1,2}", which matches from 1 to up to 2 digits only. So, you probably want to change that to "\\d+" (1 or more times) or "\\d{1,3}" (in case you want to match from 1 to up to 3 digits). This is all explain on the API page of the Pattern class: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

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