-1

What does this ((\d\d\d)\s)? regex match?

Moses Kirathe
  • 132
  • 1
  • 2
  • 14

4 Answers4

1

\d matches the digits. it is all about the langugae you are using. In python3, [0-9] matches only 0123456789 characters, while \d matches [0-9] and other digit characters, for example Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩.

  • \s matches any whitespace character
0

have a look at this site https://regex101.com/r/yS5fU8/2

1st Capturing Group (\d\d\d)

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

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

Subhashi
  • 3,619
  • 1
  • 20
  • 20
0

\d matches digits from [0-9].

\s matches white-space characters like [ \t\n\r]

? is means optional, it matches even if the following regex are not present.

() are used for grouping.

Now the question is what does ((\d\d\d)\s)? match? \d\d\d matches 3 consecutive digits and group them to $1.

((\d\d\d)\s) matches 3 consecutive followed by space and this is grouped to $2.

since we have ? at the end of the regex, it matches digits followed with space and also if there are no such match.

In case if there is no match, it points to start of the line.

0

The regex expression : enter image description here

The first backslash escapes the open parenthesis that follows, as it is a special character, so the regex will search for an open and a close parenthesis in the input string

Example : (111)

Moses Kirathe
  • 132
  • 1
  • 2
  • 14