Issue with string matching and extraction with Regex

Hello!

I’m a noob with RF and I’m pulling may hair out about what I would assumbe is a basic issue.

I’m interacting with SAP, but the issue at hand has not to do with this but with a simple string matching with Regexp in which I need to extract a matching group.

In line 29 I successfully obtain a key part of the Window title into the var $MatchResult, which has a value of [‘Unl’]. On line 37 I compare it to the string “Unl” but it neces evaluates to true.

I’ve tried using MatchResult as @MatchResult and accesing the [0] element, assuming that the value is the first item in the lint and it doesnt work either.

I’ve also tried matching it to “[‘Unl’]” literal and still same result, with $MatchResult as scalar value.

What is the actual return from String.Get Regep Mathes when you have a match group? I was expecting it to be a List but it seems not to be like that…

Help!

Hi

This is because Get Regexp Matches returns a list of all non-overlapping matches in the given string.

You can use the below two ways, among others, to handle it, but either or as an example below to replace that on line 37:

IF    """${MatchResults}[0]""" == """Unl"""   
IF   "Unl" in ${MatchResults}

I hope that helps :slight_smile:

link to the playground for working example

1 Like

Worked like a charm! Thank you very much!!

Used the second option as it seems more readable.

2 Likes