Regex String Not Working
-
Hey!
Had a bit of a regex problem. I basically want to use
Engine.getRegexMatches
to return me a value. Basically, I want to find all values after the following substring:" - "
(it has spaces and ignore quotes) . For example, if the given string was:Thanks - For Helping
. The result should beFor Helping
. I tried the following code:".*? - "
(ignore quotes) in regexr, But the result in hise is the opposite from what I want, I don't know if there is a way to invert the value to show the other part after" - "
. Then I tried this code:"(?<= - ).*$"
(ignore quotes) and it worked flawlessly, but when put into hise as a string, an error in the console pops up calledInterface:! regex_error(error_syntax)
Anyone know what could be wrong here?Thanks!
-
@Casmat I'm not familiar with regex but if it's working for your purpose you could use substring
const strings = ["Thanks - For Helping", "Vielen dank - My Dear"] for (s in strings) Console.print(s.substring(s.indexOf("-")+1, s.length).trim());
logging:
Interface: For Helping Interface: My Dear
-
s.split("-")[1].trim()
should do the trick too. Regex is overkill for this simple task, but the correct syntax for this would beconst strings = ["Thanks - For Helping", "Vielen dank - My Dear"] for(s in strings) Console.print(Engine.getRegexMatches(s, ".* - (.*)")[1].trim());
-
@ulrik @Christoph-Hart Thanks! Both work amazing! The trim() function was exactly what I was looking for! I had thought it cut out all whitespace characters, not just the start and end! Thanks for helping!