Jump to content
Ketarin forum

Regular expressions - adding trailing zeros


Dji
 Share

Recommended Posts

Hi,

 

I would like to add trailing zeros of a variable when I encounter a version number without it:

 

Examples:

if initial version 5.57 ->  version is 5.57

but :

if initial version 5.8 ->  version would be 5.80 and not 5.8

 

In such cases I usually use regular expression replacements but the following regular regexpression syntaxes does not works unfortunatey...

 

{version:regexreplace:^(\d+)\.(\d)(?!\d)$:$1.$20}                     -> result is 5.$20  can't work of course, group 20 is unknown

{version:regexreplace:^(\d+)\.(\d)(?!\d)$:$1.$2\0}                     -> result is 5.8\0  escape character doesn't work as well

{version:regexreplace:^(\d+)\.(?<first>\d)(?!\d)$:$1.${first}0}   -> result is 5.${first0}  group name is unkown !

{version:regexreplace:^(\d+)\.(?<first>\d)(?!\d)$:$1.${first\}0}  -> result is 5.${first}0  group name is unkown even using escape character !

 

Help required, thanks ! :)

Link to comment
Share on other sites

I tried your first regex, and it worked fine for me. Are you using the latest Ketarin beta (1.7.0 b2) ?

Try the following regex, and see if its work:

{version:regexreplace:^\d+\.\d$:$00}

 

If still not working, than create a textual variable with the name "version1" :

{version:regexreplace:^\d+\.\d$:$0#}

 

And now you can use replace to add the zero:

{version1:replace:#:0}

 

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.