-1

What is the output of this regular expression?

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

In particular what is the meaning of /\s

Toto
  • 89,455
  • 62
  • 89
  • 125
jbot
  • 133
  • 1
  • 2
  • 8

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
  • 4,399
  • 34
  • 43
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)
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
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
  • 494
  • 5
  • 18