How to use a ":" (colon) within a regex within replaceFirst, in a message template?

I need to improve the collection of statistics for a url:
/path/{clientId}

Currently, the report is being generated erratically, Apigee is understanding that each {clientId} is a different URL.

The solution I found for this was:

 

 

<AssignVariable>
   <Name>custom-path</Name>
   <Template>/path/{replaceFirst(proxy.pathsuffix,'^.path.REGEX','clientId')}</Template>
</AssignVariable>

 


In other urls it worked perfectly, but specifically in this one it didn't. It's not working because there is ":" in the clientId field.

example clientId:  xxx:org-x:xx10x10x-10x1x0-x10

regex that deals with this field: 

 

<AssignVariable>
   <Name>custom-path</Name>
   <Template>/path/{replaceFirst(proxy.pathsuffix,'^.path.xxx:[a-z|-]+:[a-z0-9]+','clientId')}</Template>
</AssignVariable>

 

Even validating the regex (at https://regex101.com/), I'm not able to make apigee understand the ":".

 

How do I know the error is the ":"?

if I change the input to: xxx-org-x-xx10x10x-10x1x0-x10
AND

Change the regex like this:

 

<AssignVariable>
   <Name>custom-path</Name>
   <Template>/path/{replaceFirst(proxy.pathsuffix,'^.path.[a-z0-9|-]+','clientId')}</Template>
</AssignVariable>

 

That way it works.

 

How do I make apigee understand the ":"?

Solved Solved
1 1 518
1 ACCEPTED SOLUTION

augh. sorry about that. 

The problem, I think, is the logic that parses  "replaceFirst" is choking on the colon. But you can work around that issue by embedding the actual regex in a variable, and referring to it in the replaceFirst function. 

Something like this. 

<AssignVariable>
   <Name>regex1</Name>
   <Value>^.path.xxx:[-a-z]+:[-a-z0-9]+</Value>
</AssignVariable>
<AssignVariable>
   <Name>custom-path</Name>
   <Template>/path/{replaceFirst(proxy.pathsuffix,regex1,'clientId')}</Template>
</AssignVariable>

 

View solution in original post

1 REPLY 1

augh. sorry about that. 

The problem, I think, is the logic that parses  "replaceFirst" is choking on the colon. But you can work around that issue by embedding the actual regex in a variable, and referring to it in the replaceFirst function. 

Something like this. 

<AssignVariable>
   <Name>regex1</Name>
   <Value>^.path.xxx:[-a-z]+:[-a-z0-9]+</Value>
</AssignVariable>
<AssignVariable>
   <Name>custom-path</Name>
   <Template>/path/{replaceFirst(proxy.pathsuffix,regex1,'clientId')}</Template>
</AssignVariable>