summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/regex/regex.cpp16
-rw-r--r--modules/regex/regex.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp
index 00e8ce0f54..daadfcc659 100644
--- a/modules/regex/regex.cpp
+++ b/modules/regex/regex.cpp
@@ -324,6 +324,21 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end)
return result;
}
+Array RegEx::search_all(const String &p_subject, int p_offset, int p_end) const {
+
+ int last_end = -1;
+ Array result;
+ Ref<RegExMatch> match = search(p_subject, p_offset, p_end);
+ while (match.is_valid()) {
+ if (last_end == match->get_end(0))
+ break;
+ result.push_back(match);
+ last_end = match->get_end(0);
+ match = search(p_subject, match->get_end(0), p_end);
+ }
+ return result;
+}
+
String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_all, int p_offset, int p_end) const {
ERR_FAIL_COND_V(!is_valid(), String());
@@ -489,6 +504,7 @@ void RegEx::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &RegEx::clear);
ClassDB::bind_method(D_METHOD("compile", "pattern"), &RegEx::compile);
ClassDB::bind_method(D_METHOD("search", "subject", "offset", "end"), &RegEx::search, DEFVAL(0), DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("search_all", "subject", "offset", "end"), &RegEx::search_all, DEFVAL(0), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("sub", "subject", "replacement", "all", "offset", "end"), &RegEx::sub, DEFVAL(false), DEFVAL(0), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("is_valid"), &RegEx::is_valid);
ClassDB::bind_method(D_METHOD("get_pattern"), &RegEx::get_pattern);
diff --git a/modules/regex/regex.h b/modules/regex/regex.h
index bfa9c84042..21387222f2 100644
--- a/modules/regex/regex.h
+++ b/modules/regex/regex.h
@@ -88,6 +88,7 @@ public:
void _init(const String &p_pattern = "");
Ref<RegExMatch> search(const String &p_subject, int p_offset = 0, int p_end = -1) const;
+ Array search_all(const String &p_subject, int p_offset = 0, int p_end = -1) const;
String sub(const String &p_subject, const String &p_replacement, bool p_all = false, int p_offset = 0, int p_end = -1) const;
bool is_valid() const;