Hii can anyone tell me meaning of the given re?
pr\s+stats\s+(\d+)(?:hours|hrs)
i am confused about \s and \d soo i need explanation
Hii can anyone tell me meaning of the given re?
pr\s+stats\s+(\d+)(?:hours|hrs)
i am confused about \s and \d soo i need explanation
Have a look at this link to see what are the kind of strings that are matched by this regex: https://regex101.com/r/7LXIrb/1
Examples:
pr stats 123hours << matched
pr stats 432hours << matched
pr stats 4hrs << matched
pr
stats
1hrs
^^^^^^^
matched
#######
pr
stats
199hrs
^^^^^^^
matched from pr
Explanations:
pr
followed by stats
reference for regex: http://www.rexegg.com/regex-quickstart.html
pr
=> the string contains 'pr'
\s+
=> it is followed by one or more space
stats
=> it is followed by the word 'stats'
\s+
=> it is followed by one or more space
(\d+)
=> it is followed by one or more digit (from 0 to 9)
(?:hours|hrs)
=> it is followed by the string 'hours' or the tring 'hrs'
Exemple of strings that would match :
pr stats 45hours
uifyerrpr stats 45hoursoudfghsofh
pr stats 45hrs
Exemple of strings that would not match :
pr stats45 hours
uifyerrprstats 45 hoursoudfghsofh
pr stats hrs
pr stats 45hour