简体   繁体   中英

Is there a way to combine discontinuous capture groups in a single regex?

I am using C++ RE2. I want to save concatenated discontinuous capture groups in result string. The Regex itself may have one or more capture groups.

RE2::PartialMatch(sourceStr, Regex, &result)

Example

sourceStr = "This is an example."
Regex = "(This).*(example)"
result = "Thisexample"

How can I accomplish this?

You could try:

string result = sourceStr;
RE2::Replace(&result, "(This).*(example)", "$1$2");

Why use an outside library when you have the library already existing in the studio itself. Use it with the "match function. A link to refer for further learning: https://en.cppreference.com/w/cpp/regex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM