-1

What is the output of this regular expression?

/\s+(\d+)\s+/

In particular what is the meaning of /\s

Toto
  • 83,193
  • 59
  • 77
  • 109
jbot
  • 63
  • 1
  • 5

3 Answers3

0

In your regex \s+ matches any number of whitespaces sequentially and /d+ matches any number of digits sequentially .

\s and \d matches a single whitespace and single digit respectively the + makes it match any number of sequential whitespaces and digits respectively.

Thanthu
  • 2,648
  • 19
  • 36
0

You can find a full explanation at regex101.com.

/\s+(\d+)\s+/

\s+ matches any whitespace character (equal to [\r\n\t\f\v ])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)

1st Capturing Group (\d+)

\d+ matches a digit (equal to [0-9])

+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)

\s+ matches any whitespace character (equal to [\r\n\t\f\v ])

+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
Always Sunny
  • 29,081
  • 6
  • 43
  • 74
0

https://regex101.com/

might be useful :D

\s+(\d+)\s+ / ↵ matches the character ↵ literally (case sensitive) \s+ matches any whitespace character (equal to [\r\n\t\f\v ]) + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy) 1st Capturing Group (\d+) \d+ matches a digit (equal to [0-9]) + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy) \s+ matches any whitespace character (equal to [\r\n\t\f\v ]) + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed

Debugger
  • 461
  • 5
  • 17