# Regular expression

**URL:** <https://forum.robotframework.org/t/regular-expression/3599>\
**Category:** Robot Framework\
**Created:** [12 April 2022 14:15 UTC](https://forum.robotframework.org/t/regular-expression/3599 "2022-04-12T14:15:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morad\_Elkhaily](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@Morad\_Elkhaily](https://forum.robotframework.org/u/Morad_Elkhaily)\
**Post date:** [12 April 2022 14:15 UTC](https://forum.robotframework.org/t/regular-expression/3599/1 "2022-04-12T14:15:20Z")

</div>

Hi Everyone,

I have this Variable as the return of my query :  
${query} = ((b’\x01’, ‘Morad’, datetime.datetime(2022, 4, 12, 15, 18, 57)),)

Can any one plz help me to extract the information from it using regex as bellow:  
1  
Morad  
2022, 4, 12, 15, 18, 57

Regards

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [12 April 2022 14:30 UTC](https://forum.robotframework.org/t/regular-expression/3599/2 "2022-04-12T14:30:16Z")

</div>

Hi Morad,

regex101 is a really useful site for playing with, learning and testing regex patterns

`\\x(\d*)[^‘]*‘(\w*)[^\(]*\(([^\)]*)` [follow this link to see how it works on regex101.com](https://regex101.com/r/Zh6zdH/1)

Dave.

---

<div class="post-metadata">

**Author:** ![Morad\_Elkhaily](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@Morad\_Elkhaily](https://forum.robotframework.org/u/Morad_Elkhaily)\
**Post date:** [12 April 2022 15:50 UTC](https://forum.robotframework.org/t/regular-expression/3599/3 "2022-04-12T15:50:48Z")

</div>

Hi Dave,  
Thanks for your help.  
i try to implement it but it doesn’t work in my code.  
This is how i implement it :  
${query} = DatabaseLibrary.Query SELECT FLAG,USER,DATE FROM record WHERE test = ‘63661446’

```
${result} = Get Regexp Matches ${query} \\x(\d*)[^‘]*‘(\w*)[^\(]*\(([^\)]*)

error: incomplete escape \x at position 0
```

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [13 April 2022 08:19 UTC](https://forum.robotframework.org/t/regular-expression/3599/4 "2022-04-13T08:19:26Z")

</div>

Ho Morad,

In robot framework you need to escape the \'s:

```python
${result} = Get Regexp Matches ${query} \\\\x(\\d*)[^‘]*‘(\\w*)[^\\(]*\(([^\\)]*)

```

In regex you also need to escape the \'s as well, so this is what’s often referred to as double escaping, your original string had `\x01` to match the `\x` part in regex we need to escape it as `\\x` and then for the robot framework we also need to escape again so we get `\\\\x`.

The `\d` is a special regex command that means any digit, so we only need to escape it once for robot framework, it becomes `\\d`, likewise for `\w`. `\(` and `\)` are needed because `(` and `)` also need to be escaped because they have special meaning in regex they are the group identifier.

Hope that clears it up for you.

Dave.

---

<div class="post-metadata">

**Author:** ![Morad\_Elkhaily](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@Morad\_Elkhaily](https://forum.robotframework.org/u/Morad_Elkhaily)\
**Post date:** [13 April 2022 11:28 UTC](https://forum.robotframework.org/t/regular-expression/3599/5 "2022-04-13T11:28:17Z")

</div>

Hi Dave,  
Its totally clear.  
The question is why it not working when i test it .  
it Show me this error msg:  
`error: missing ), unterminated subpattern at position 25`

---

<div class="post-metadata">

**Author:** ![pekkaklarck](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/pekkaklarck/32/1019_2.png) [@pekkaklarck](https://forum.robotframework.org/u/pekkaklarck)\
**Post date:** [13 April 2022 12:38 UTC](https://forum.robotframework.org/t/regular-expression/3599/6 "2022-04-13T12:38:46Z")

</div>

The result seems to be a nested Python tuple (or a string representation of a such tuple). Instead of using regexps, I’d access items directly. If it’s a real tuple, you ought to be able to get all values like this:

```python
${x} ${y} ${z} = Set Variable ${query}[0]

```

Notice also that `b'\x01'` isn’t number 1 it’s byte 1.
