_MikeW_
Enthusiast
Enthusiast

vRO 8.1, Regular Expression specifications.

Jump to solution

I am having issues trying to parse some text with regular expressions in a vRO 8.1 workflow.

This is suppose to get the prefix for a network. For example in 10.0.0.1/24 it should populate the variable v4Prefix with "24".

const ipv4Network = /^.*\/(\d+)$/g;

const v4Prefix = context.ipv4cidr.match(ipv4Network);

System.log("v4Prefix =" + JSON.stringify(v4Prefix));

When testing the regular expression in various other tools it will give me the prefix of 24, when I do this within the workflow v4Prefix returns the entire contents "ipv4cidr" of 10.0.0.1/24 in v4Prefix instead of just "24".

Does the javascript implementation within vRO have limitations and if so where can I find those detailed?

Tags (2)
1 Solution

Accepted Solutions
_MikeW_
Enthusiast
Enthusiast

That was exactly the problem. I removed /g and was able to get what I expected.

Working code was:

context.ipv4cidr = "10.1.1.0/24";

const ipv4Network = /^.*\/(\d+)$/;

const v4Prefix = context.ipv4cidr.match(ipv4Network)[1];

v4Prefix = 24

View solution in original post

2 Replies
emacintosh
Enthusiast
Enthusiast

What is the "context" object in your script?  It would seem like you are matching the entire string, even if you are specifying a capture group.  I think I read somewhere that the global flag isn't compatible with capturing groups as well, but that could have been on a random site and incorrect/irrelevant.

In any case, I put together a quick action in 8.1, and this code returns "24" and logs the following:    10.10.10.10/24,24

var cidr = "10.10.10.10/24"

var regex = /.*\/(\d+)$/;


var matches = cidr.match(regex);

System.log(matches);


return matches[1];

0 Kudos
_MikeW_
Enthusiast
Enthusiast

That was exactly the problem. I removed /g and was able to get what I expected.

Working code was:

context.ipv4cidr = "10.1.1.0/24";

const ipv4Network = /^.*\/(\d+)$/;

const v4Prefix = context.ipv4cidr.match(ipv4Network)[1];

v4Prefix = 24

View solution in original post