help with extracting text with variable in regex

solquest

Member
Hey there.
I need some help with Extract text action.
When I get notifications like this one
18' Gol! [1] - 0 Jovic L.
I have an action 'Extract text' for saving the result in a variable (result) -in this case result = [1] - 0. And this works always fine.
Then I have another Extract text action for getting the scorer.
The regex is
(?s)(?<=\{v=result} )(.*?)((?=\b ?.\.)|$)
and in that case I would get 'Jovic'.

The problem is that the result could also be 0 - [1] and in this case that regex is giving an error (I guess for having not the escape before [1]):
Error with text manipulation: java.util.regex.PatternSyntaxException: Unrecognized backslash escape sequence in pattern near index 11
(?s)(?<=\0 - [1] )(.*?)((?=\b ?.\.)|$)

I've tried adding another Text Manipulation action before that regex, for replacing '[' with '\[' (and then using the regex (?s)(?<={v=result} )(.*?)((?=\b ?.\.)|$)) but that replace action is giving me the error: Error with text manipulation: java.util.regex.PatternSyntaxException: Missing closing bracket in character class near index 1 [

How can I manage to have a regex working in both cases?
Tanks.
Luigi.
 

Endercraft

Moderator (& bug finder :D)
You can always try asking ChatGPT, it's pretty good at this stuff.

May this work :
(?s)(?<=\0 - \[1\] )(.*?)((?=\b ?.\.)|$)
 

solquest

Member
I know that can work, my problem is that I need to have a variable inside that regex, cause that result can change.

Thanks.
 

Endercraft

Moderator (& bug finder :D)
java.util.regex.PatternSyntaxException: Unrecognized backslash escape sequence in pattern near index 11
(?s)(?<=\0 - [1] )(.*?)((?=\b ?.\.)|$)
Comes from \0

I've tried adding another Text Manipulation action before that regex, for replacing '[' with '\[' (and then using the regex (?s)(?<={v=result} )(.*?)((?=\b ?.\.)|$)) but that replace action is giving me the error: Error with text manipulation: java.util.regex.PatternSyntaxException: Missing closing bracket in character class near index 1 [
You need to replace \[ by \[ as the replace all field is also regex so you need to use \[ to match [.
 
Top