-1

What is the output of this regular expression?

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

In particular what is the meaning of /\s

Toto
  • 86,179
  • 61
  • 85
  • 118
jbot
  • 93
  • 2
  • 6

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
  • 3,526
  • 28
  • 39
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
  • 32,751
  • 7
  • 52
  • 86
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
  • 484
  • 5
  • 18