-2

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

  • The characters "pr" followed by at least one whitespace character, followed by "stats", followed by at least one whitespace character, followed by one or more digits (which are captured in a capture group), followed by either "hours" or "hrs". – L3viathan Jan 18 '18 at 12:03
  • look [here](https://regex101.com/r/OuxLJ6/1) at the right panel to understand it. – Reborn Jan 18 '18 at 22:03

2 Answers2

0

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
  • 1 or more "whitespace char" ( space, tab, newline, carriage return, vertical tab)
  • followed by stats
  • then 1 or more "whitespace char" ( space, tab, newline, carriage return, vertical tab)
  • then one or more digits in a capturing group
  • then in a non capturing group hours or hrs

reference for regex: http://www.rexegg.com/regex-quickstart.html

Allan
  • 11,170
  • 3
  • 22
  • 43
0

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
Leyff da
  • 206
  • 3
  • 13