python - searching for doubles with regular expressions -


this question has answer here:

is there regular expression match floating point numbers not if part of construct 15.01.2016?

re.match(rex, s) should successful if s be

1.0a 1.b .1 

and not successful s like

1.0.0 1.0.1 20.20.20.30 12345.657.345 

edit: crucial part combination of constrains: "[0-9]*\.[0-9]*" , not part of "[0-9]+\.[0-9]+(\.[0-9]+)+"

you can use regex based on arounds in python:

(?<![\d.])(?:\d*\.\d+|\d+\.\d*)(?![\d.]) 

regex demo

  • (?![\d.]) lookahead assertion fail match if next char dot or digit
  • (?<![\d.]) lookbehind assertion fail match if previous char dot or digit

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -