Skip to main content
Archived

Add option to string function 'ReplaceRegEx(str, regExp, newStr, [caseSensitive]

Related products:Transformers

thijsknapen
Contributor

***Note from Migration:***

Original Title was: Add option to string function 'ReplaceRegEx(str, regExp, newStr, [caseSensitive])' on what value to return in case no matches are found (similar to the option in the equivalent stringreplacer transformer)


I hope the title is self explanatory. Today I was using the string function 'ReplaceRegEx(str, regExp, newStr, [caseSensitive])', and found out that in case no match is found by the regExp, the 'newStr' is set to 'str'.

To start, I think it would be nice if a description on the behaviour of this function in case no matches are found, could be added to the string function documentation.


Depending on what you aim to achieve with the function, the default behaviour can be a bit confusing. For my case it would have been better to have the option to set the value to an empty string (as I was using the string function to replace the original string, with parts of the original string, using replacements based on 'capturing groups' of regex). However, I can also imagine that in most use cases the preferred default behaviour would indeed be to return the original string in case no match is found.


In the equivalent stringreplacer transformer it is possible to specify a value in case the attribute value does not contain the text/regex, by using the option 'Set Attribute Value To'. It would be nice if this option can also be added to the string function (as an optional parameter?).

This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings