-
Notifications
You must be signed in to change notification settings - Fork 115
RegEx
regex_replace(base.request.url.path, "/$", "")}
To trim the path variable to 42 characters, one can use: regex_replace({path}, "?<=^.{42}).*" , "")
The logic behind this one is to use two regex_replace statements and feed the results of one into the other, so we can replace the beginning and end of the string with "" and leave ourselves with the bit in the middle we’re interested in.
For example, if we wanted to use this to find data in the middle of the request body:
-
First of all, trim off the end of the string using:
{regex_replace({base.request.body},"<insert_your_regex_here>","")}
-
Then take that and use it as the string source for the next regex_replace and trim off the beginning of the string
{regex_replace{{regex_replace({base.request.body},"<insert_your_regex_here>","")},"insert_your_regex_here>",""}
You can use capture groups in regex_replace, which could be useful for inserting details into the middle of a string, for example:
If you have the following URL
https://ginandjuice.shop/test1/test2/
You could use the following regex_replace statement to insert another level into the middle of the path
{regex_replace(base.request.url.path,"(^.*\/)(.*\/$)","mynewpath/")}
To get
https://ginandjuice.shop/test1/mynewpath/test2/