# Issue with string matching and extraction with Regex

**URL:** <https://forum.robotframework.org/t/issue-with-string-matching-and-extraction-with-regex/7227>\
**Category:** Robot Framework\
**Created:** [28 April 2024 13:35 UTC](https://forum.robotframework.org/t/issue-with-string-matching-and-extraction-with-regex/7227 "2024-04-28T13:35:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elbenco](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@Elbenco](https://forum.robotframework.org/u/Elbenco)\
**Post date:** [28 April 2024 13:35 UTC](https://forum.robotframework.org/t/issue-with-string-matching-and-extraction-with-regex/7227/1 "2024-04-28T13:35:40Z")

</div>

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.

 ![RF1](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/2/200c15989a3442ba65c2b48cd562ecbc719dc6e5.png)

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!

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [28 April 2024 14:48 UTC](https://forum.robotframework.org/t/issue-with-string-matching-and-extraction-with-regex/7227/2 "2024-04-28T14:48:16Z")

</div>

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 🙂

link to the playground for working [example](https://robotframework.org/code/?codeProject=N4IgdghgtgpiBcIDCBXAzgFwPZRAGhABMY0BjAJwEsAHDSrMBEfEAM0oBsSEBtUdrgDlocRABUSGAMopKGGADpyWAEZYMLUg3lgNiAFSGABFJgY6YAOZojh-QB0wAGUoryEcgE8jPn1IxUVo6OdkYSmEZIEGgktoaO4RiR0TBGAIyOvkYAJMAAshAYpAAWAEokKBwYaAC+ALxZAOJmRuWWMAAe1EYFRcWxvgAiUgAsABRpAJQA9ADMAAzzRgCqYBxYpADWKzHkRgCiABoA+gCC+1Kl+05Op1lZ9o-2UgDURmMKL5Mb28u7Rk9nm97r4MmAsrkuGB6iCfM0kk4YFYMMUIflCiVymhKtUaplfPifABiIwASQAYg8QPZqSBcr1MRUqrUePMALo0zkgIx1BpcmmrDj87k+QlkymikCCmlGSjg+kYspM3FirJOLCWMJYSIMNBYLj3UkYADkNgg4IZxTF1yk+1VvnVmrE2qQuv1qSyRtNRjA6iMECMUEV1sEg0cIBqbIIxCoADcYIQAArKABWMFIegCKBgBGUagwADUYOQ0PRGIgAOwKeYsPPqU7kawIYA1XMwACOsnIMFgujQvDZNSAA)

---

<div class="post-metadata">

**Author:** ![Elbenco](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@Elbenco](https://forum.robotframework.org/u/Elbenco)\
**Post date:** [28 April 2024 15:00 UTC](https://forum.robotframework.org/t/issue-with-string-matching-and-extraction-with-regex/7227/3 "2024-04-28T15:00:56Z")

</div>

Worked like a charm! Thank you very much!!

Used the second option as it seems more readable.
