walli
walli

Reputation: 37

Simple regex for C++

I'm new to regexes and I'm trying to find a regex that matches :randomNumberOfWhitespacesOrNothing:

I've tried something like this :([\s\S]*): but it didn't work. Can anyone help me?

Upvotes: 1

Views: 39

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626689

The \S pattern matches any non-whitespace symbol. Remove it from your character class and use

:(\s*):

See the regex demo

Details:

  • : - a colon
  • (\s*) - capturing group with ID 1 that matches 0+ (due to * quantifier) whitespace symbols
  • : - a colon.

Upvotes: 1

Related Questions