Reputation: 25
I have a string "SolutionAN ANANANA SolutionBNabcabcSolutionX"
and I want to return all string which start with Solution
and end just before sub string Solution
.
While using boost::regex
I am unable to make regular expression for it.
I want to get SolutionAN ANANANA
, SolutionBNababc
and SolutionX
as output. I am new to regex in boost, any help will be appreciated.
Upvotes: 0
Views: 170
Reputation: 32797
You can use this regex
(?s)Solution.*?(?=Solution|$)
.*?
would match 0 to many characters lazily i.e it eats as less as possible.
Without ?
it would become greedy and eat as much as possible.
x(?=yz)
is a lookahead which matches x only if it is followed by yz
$
is the end of string
.
by default won't match newline character..You should use (?s)
modifier within regex or use mod_s
option which causes .
to match newline character
Upvotes: 1