Regex expression for pattern matching

I am accepting string something like "libInterpreterCommon.so.18.5" from user and validating whether the entered string matches the above pattern after the first dot it should be "so" and after second dot character it should be two digit number and after the third dot character it should be only single digit number.

Not getting exact way for matching the above string.

1 answer

  • answered 2018-11-08 09:05 Beri

    This regexp should solve this issue:

    \.so\.[0-9]{2}\.[0-9]$
    

    \. - this will escape the dot, otherwise it would accept any character

    [0-9]{2} - two digits

    [0-9] -single digit

    $ - this means the end of the input. Otherwise your regexp would accept strings that do not end after last digit.