Re: Assistance with "Replace String Using Regexp"

2,394 views
Skip to first unread message

Tatu aalto

unread,
Oct 20, 2012, 3:24:07 AM10/20/12
to dennis...@gmail.com, robotframe...@googlegroups.com

Ugh

Perhaps it would be better use String library Get Substring [1] and BuiltIn library Catenate keywords.

Split the string from correct point in two portions. Then use the Catenate to add the comma as correct separator.

-Tatu

[1] http://robotframework.googlecode.com/hg/doc/libraries/String.html?r=2.7.4#Get%20Substring
[2] http://robotframework.googlecode.com/hg/doc/libraries/BuiltIn.html?r=2.7.4#Catenate

On Oct 20, 2012 9:49 AM, "Dennis Marwood" <dennis...@gmail.com> wrote:
Hello,
 
I would like to replace 12345 with 12,345. I am running into issue with the replace portion of the regex.
 
${MYTest}=     Replace String Using Regexp      ${MYTest}      (\\d{3}(?!$)))     $1,
Could someone point me in the correct direction here? Or is there a better way to add commas to numbers?
 
Thanks.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/robotframework-users/-/dvo8PA94T70J.
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.

wilco

unread,
Oct 21, 2012, 3:50:16 PM10/21/12
to robotframe...@googlegroups.com
Dennis,

You were on the right track but your regex was a little messy. Also, you don't refer to matched groups with $n, but rather \\n.  I was able to get what you needed with the following:

${test}= Replace String Using Regexp 654321 (\\d{3}$) ,\\1

Running this and logging the output:
[ WARN ] 654,321

This regex only works, however, for numbers less than 999999.  If you wanted to match those, you'll have to construct a more complicated regex that will match middle three numbers.  Or, you can use Split String keywords in conjunction with this to do what you need.

Hope this helps,
Roj

Dennis Marwood

unread,
Nov 5, 2012, 7:39:09 PM11/5/12
to robotframe...@googlegroups.com
Thanks for the responses.
Reply all
Reply to author
Forward
0 new messages