------------------------------------------------------------------------------
| 48 | vtksys::RegularExpression RegExNodeIdInExpression = "[a-zA-Z0-9]+"; |
| 49 | //------------------------------------------------------------------------------ |
| 50 | void ReplaceStringUsingRegex(std::string& source, vtksys::RegularExpression& regex, |
| 51 | const std::string& replace, const std::string& with) |
| 52 | { |
| 53 | // find all matches |
| 54 | std::vector<std::string> matches; |
| 55 | for (size_t next = 0; regex.find(source.substr(next)); next += regex.end()) |
| 56 | { |
| 57 | const auto mathWord = source.substr(next + regex.start(), regex.end() - regex.start()); |
| 58 | if (mathWord == replace) |
| 59 | { |
| 60 | matches.push_back(mathWord); |
| 61 | } |
| 62 | } |
| 63 | // replace all matches |
| 64 | for (const auto& match : matches) |
| 65 | { |
| 66 | const auto pos = source.find(match); |
| 67 | if (pos != std::string::npos) |
| 68 | { |
| 69 | source.replace(pos, match.length(), with); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | //------------------------------------------------------------------------------ |