regular expression

2,392 views
Skip to first unread message

vishnu vasudev

unread,
Mar 1, 2016, 11:44:01 AM3/1/16
to robotframework-users
Hi,
i am using robot framework for a gui automation

here my 

${text} = extend to 2016.12.31

looks like this.

I would like it to be without the characters like this

${text} = 2016.12.31

can you please let me know a regular expression by which i can do that

Regards
Vishnu

Hélio Guilherme

unread,
Mar 1, 2016, 12:23:09 PM3/1/16
to robotframework-users

This is a possible solution of a regular expression for your case:
"\d{4}[.]\d{2}[.]\d{2}"

I used the https://regex101.com/#python to test that expression.

Other option is to use the String library, for example splitting the text by ${SPACE} and getting the last value (the date) or you could use a keyword to remove all words from text. This is the doc for a keyword you could try: Split String From Right

 

vishnu vasudev

unread,
Mar 1, 2016, 12:55:15 PM3/1/16
to heliox...@gmail.com, robotframework-users
Hello Robot,
Thanks alot for kind suggestion.

I was not able to get a keyword in robot framework to get this working.

i used the following 
${final}= Get Lines Matching Regexp ${text} \d{2}[.]\d{2}[.]\d{4}

where ${text}=extend to 31.12.2016

BUt it failed with these logs
KEYWORD BuiltIn . Log ${text}
Documentation:

Logs the given message with the given level.

Start / End / Elapsed: 20160301 23:17:26.997 / 20160301 23:17:26.997 / 00:00:00.000
23:17:26.997 INFO extend to 31.12.2016
00:00:00.000 KEYWORD ${final} = String . Get Lines Matching Regexp ${text}, \d{2}[.]\d{2}[.]\d{4}
Documentation:

Returns lines of the given string that match the regexp pattern.

Start / End / Elapsed: 20160301 23:17:26.997 / 20160301 23:17:26.997 / 00:00:00.000
23:17:26.997 INFO 0 out of 1 lines matched
23:17:26.997 INFO ${final} =
00:00:00.000 KEYWORD BuiltIn . Log ${final}

Regards
Vishnu

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Hélio Guilherme

unread,
Mar 1, 2016, 1:23:49 PM3/1/16
to robotframework-users, heliox...@gmail.com


terça-feira, 1 de Março de 2016 às 17:55:15 UTC, vishnu vasudev escreveu:
Hello Robot,
Thanks alot for kind suggestion.

My name is Hélio (reads like Elyu  E like in Eolic).
 
I was not able to get a keyword in robot framework to get this working.

i used the following 
${final}= Get Lines Matching Regexp ${text} \d{2}[.]\d{2}[.]\d{4}

That is a different question.
That keyword is expecting an exact match (and it uses /^ and $/ from beginning to end). You must "try" \w{2}\d{2}[.]\d{2}[.]\d{4} or .*\d{2}[.]\d{2}[.]\d{4} but you will get the complete line.
If you are using RF > 2.9 you can use the option partial_match=True.
Take care that in Python/RF the (\)  may have to be escaped with another (\\).

After getting the lines you will have to do more filtering like I explained before.

Kolambe, Jayashree

unread,
Mar 2, 2016, 1:25:57 AM3/2/16
to vishnuva...@gmail.com, robotframework-users

You want to remove extend to text from ‘extend to 2016.12.31’ correct?

You can do that with following:

${text}=               Replace String    ${text}    extend to         ${EMPTY}

 

With above, you will now have only date in ${text}

--

vishnu vasudev

unread,
Mar 2, 2016, 10:39:44 AM3/2/16
to Kolambe, Jayashree, robotframework-users
Hi Jayashree.
the one problem is that the line containing the info can vary.
it would be any characters with the date at the end,
So either i have to remove the letters from the line or spilt the line to get the date.
i guess then this command cannot work out since i have to give the string here.

Hi Hélio,
i tried to split the line based on your advice.
seems to work well :)

Thanks alot Jayashree and Hélio 

Regards
Vishnu

Kolambe, Jayashree

unread,
Mar 3, 2016, 10:34:58 AM3/3/16
to vishnu vasudev, robotframework-users

Try following….

${text}=    replace string using regexp     ${text}  .+[A-Za-z ]   ${EMPTY}

Reply all
Reply to author
Forward
0 new messages