1

I have a regex pattern:

boost::regex regex = "@ABC-\\d+"  

which means pattern starting with @ABC- and followed by one or more digits.
I want this pattern to be able to match this pattern one or more times that is:

boost::regex regex = "@ABC-\\d+@ABC-\\d+@ABC-\\d+@ABC-\\d+etc, etc"  
sehe
  • 374,641
  • 47
  • 450
  • 633
There is nothing we can do
  • 23,727
  • 30
  • 106
  • 194

1 Answers1

1

Use a grouping construct and apply a quantifier to it, and use ^ and $ anchors to make sure the whole string is matched against the pattern:

Example:

R"(^(@ABC-\d+)+$)"

or - with a non-capturing group that will never create a capture inside the memory buffer (this grouping construct is meant to only group subpatterns to match string sequences):

R"(^(?:@ABC-\d+)+$)"
     ^^ 

If the string can be empty, replace the last + with *: R"(^(@ABC-\d+)*$)".

Note that in C++, raw string literals are preferred when declaring regular expression patterns to avoid excessive backslashes.

Community
  • 1
  • 1
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563