Search code examples
c#regexranorex

Matching seconds and millieseconds for audio file length


I am currently working on ranorex to test the audio player , I have a button which will play the audio only for 2 seconds and the it will stopped . Once the audio stopped playing i want to validate the play position in seconds and milliseconds

My range for validation = Success is { 1,994s to 2,006s} Range for Validation = Fail is { any thing below 1,994s}

I have wrote down the regex for checking that seconds should be either 1 or 2 other than that any thing will cause validation failed Regex for seconds : ^0([1-2]{1})$

Regex for milliseconds : I want to build a regex which accepts the all number from 994 to 006

Any leads to that

Thanks


Solution

  • The pattern ^0([1-2]{1})$ could be shortened to ^[12]$, but if you would add digits behind that, due to the character class [12] all matches can start with either 1 or 2 and could lead to matching too much.

    To match from 1,994 to 2,006 you could make the pattern a bit more specific:

    ^(?:1,99[4-9]|2,00[0-6])$
    
    • ^ Start of string
    • (?: Non capture group
      • 1,99[4-9] match 1,99 and a digit 4-9
      • | Or
      • 2,00[0-6] Match 2,00 and a digit 0-6
    • ) Close group
    • $ End of string

    Regex demo