mardi 2 avril 2019

Regex: How to not match something that is followed by nothingness BUT followed by something else?

I have this fairly complex python regular expression that works the way I want it to work except one thing. I don't want it to match "." (punctuation) preceded by nothingness like this: ".". As you can see there is nothing following the dot here and I DON'T want to match that.

^unknown$|^infinite$|^-?[^0][\d]+.?(?!0)[\d]*\+?$

What the regular expression does right now is not matching a dot (".") followed by the number 0.

So 'some_string.0' will not be matched. Which is something I want to keep but I'm trying to make it not match for example '3542.'

I've tried this:

^unknown$|^infinite$|^-?[^0][\d]+.?(?!0|^$)[\d]*\+?$

Here i have inserted |^$ inside the negative lookahead assertion, but that doesn't work either now it seems it won't match anything.

^unknown$|^infinite$|^-?[^0][\d]+.?(?!0|)[\d]*\+?$

In this regex the negative lookahead assertion contains 0| And that doesn't match anything too.

What i would like is that my regular expression will not match 'somestring.' and somestring.0 but WILL match the 'someString.'... followed by any number (excluding 0 in the beginning of course) except 0 in the end.

Aucun commentaire:

Enregistrer un commentaire