正则表达式为单独的lat和long

时间:2017-07-10 16:14:12

标签: regex

我试图提出两个正则表达式,一个用于纬度值,-85.05112878< lat< 85.05112878,一个用于经度值,-180.0<长< 180.0

非常感谢帮助

1 个答案:

答案 0 :(得分:1)

不是很漂亮,你可以试试这个纬度

-85.05112878< lat < 85.05112878

^(?:-?85\.0(?:000000\d*|0{1,5}(?:[1-9]\d*)?|[1-4]\d*|5(?:0\d*)?|5(?:1(?:0\d*)?)?|511(?:[0-1]\d*)?|5112(?:[0-7]\d*)?|51128(?:[0-6]\d*)?|511287[0-8]?)?0*|(?:-[1-9]|-?[1-7]\d|-?8[0-4]|\d)\.\d+)$

扩展

 ^ 
 (?:
      -? 85
      \.0
      (?:
           000000 \d* 
        |  0{1,5} (?: [1-9] \d* )?
        |  [1-4] \d* 
        |  5 (?: 0 \d* )?
        |  5 (?: 1 (?: 0 \d* )? )?
        |  511 (?: [0-1] \d* )? 
        |  5112 (?: [0-7] \d* )? 
        |  51128 (?: [0-6] \d* )?
        |  511287 [0-8]?     
      )?
      0*
   |  
      (?:
           - [1-9] 
        |  -? [1-7] \d 
        |  -? 8 [0-4] 
        |  \d 
      )
      \. \d+ 
 )
 $

这是经度

-180.0< long < 180.0

^(?:-?180\.0+|(?:-[1-9]|-?[1-9]\d|-?1[0-7]\d|\d)\.\d+)$

扩展

 ^     
 (?:
      -? 180 \. 0+
   |  
      (?:
           - [1-9] 
        |  -? [1-9] \d 
        |  -? 1 [0-7] \d 
        |  \d 
      )
      \. \d+ 
 )
 $

修改

除了与

之类的部分(有效)形式匹配外,它与上述相同
  

54
  54.
  54.1
  等...

lat

^(?:-?85(?:\.(?:0(?:000000\d*|0{1,5}(?:[1-9]\d*)?|[1-4]\d*|5(?:0\d*)?|5(?:1(?:0\d*)?)?|511(?:[0-1]\d*)?|5112(?:[0-7]\d*)?|51128(?:[0-6]\d*)?|511287[0-8]?)?)?0*)?|(?:-[1-9]|-?[1-7]\d|-?8[0-4]|\d)(?:\.\d*)?)$

扩展

 ^ 
 (?:
      -? 85
      (?:
           \.
           (?:
               0
               (?:
                    000000 \d* 
                 |  0{1,5} (?: [1-9] \d* )?
                 |  [1-4] \d* 
                 |  5 (?: 0 \d* )?
                 |  5 (?: 1 (?: 0 \d* )? )?
                 |  511 (?: [0-1] \d* )? 
                 |  5112 (?: [0-7] \d* )? 
                 |  51128 (?: [0-6] \d* )?
                 |  511287 [0-8]?     
               )?
           )?
           0*
      )?
   |  
      (?:
           - [1-9] 
        |  -? [1-7] \d 
        |  -? 8 [0-4] 
        |  \d 
      )
      (?: \. \d* )?
 )
 $

^(?:-?180(?:\.0*)?|(?:-[1-9]|-?[1-9]\d|-?1[0-7]\d|\d)(?:\.\d*)?)$

扩展

 ^     
 (?:
      -? 180 
      (?: \. 0* )?
   |  
      (?:
           - [1-9] 
        |  -? [1-9] \d 
        |  -? 1 [0-7] \d 
        |  \d 
      )
      (?: \. \d* )?
 )
 $