2

If I process a simple string with a regex, I expect I can extract variables. The examples in the manual states that the extraction results in a stored variable. This does not work as expected. If I do the following regex:

/\w*<subtext:text>\w*/ := "myfulltextstring"

I would expect the variable subtext to contain the string text. But it is undeclared. If I declare subtext before executing, it is empty. What is the simple way to do this extraction?

NTwoO
  • 75
  • 6

1 Answers1

4

The scope of the variable subtext is not global, but "to the right of the match":

/\w*<subtext:text>\w*/ := "myfulltextstring" && bprintln(subtext)

or

if (/\w*<subtext:text>\w*/ := "myfulltextstring") {
  println(subtext);
}

or

str x = "";
if (/\w*<subtext:text>\w*/ := "myfulltextstring") {
  x = subtext;
}

Just having a declaration for subtext in an outer scope is not enough, since it would be masked by the regex variable.