#include <Core/Core.h> #include <plugin/pcre/Pcre.h> using namespace Upp; String s1 = "Too \n\n many \n\n\n newlines!", s2 = s1; RegExp reg; reg.SetPattern("(\\s*\\n\\s*)"); // find (multiple) newlines and adjacent white space String repl = "(\n)"; // trim to single newline reg.ReplaceGlobal(s1, repl); // doesn't work as expected, but deletes any match DUMP (s1); reg.ReplaceGlobal(s2, Vector<String>({"\n"})); // does work DUMP (s2);
s1 = Toomanynewlines! s2 = Too many newlines!
Vector<String> RegExp::Make_rv(const String& r) { RegExp reg("\\(((\r|\n|.)*?)\\)"); Vector<String> rv; while(reg.GlobalMatch(r)){ rv.Add(reg.GetString(0)); } return rv; }