I am attempting to learn regex and have come across a pattern that i am having trouble with - i am unable to figure how it is works exactly. What is the value of x? The language is Groovy.
x=(("World Hotel =~ /^(W....)\s+H(.*)$/))
Note that the regex ends at the
/. So we have the expression
"World Hotel =~ /^(W....)\s+H(.*)$/
which matches the string
World Hotel against the regex
^(W....)\s+H(.*)$. This will place
World into the first group, and
otel into the second capturing group. The first capturing group requires an upper-case
W at the very start of the string, followed by four arbitrary characters; after that whitespace is matched to an arbitrary non-zero length, followed by an upper-case
H; the last capturing group then matches the rest of the string until its end.
Having never used Groovy I can only speculate that the index expressions afterwards
 will retrieve the first (and only) match (
) and the second capturing group of that match (
), respectively. Which would explain the result you're seeing.
Also you seem to have one closing parenthesis too much.