Replace keyword modifier - regular expressions


(Joel Porgand) #1

I'd just like to make a request regarding the documentation for the replace keyword modifier. The documentation states "You can use regular expression values on the string that is to be replaced". This is true, but there are plenty of valid regular expressions that just won't work.

 

A proper explanation of what regular expression operations/metacharacters/etc. can and can't be used would be helpful.


(Nic Hubbard) #2

I agree. Josh did you see this post?


(Josh Sherwood) #3

Have now. Cheers. Will get on this shortly.


(Anewport) #4

Has any update to the docs been made regarding this? If not are you able to make a post when it happens Josh? Cheers


(Nic Hubbard) #5

The problem with this is that the regex that is used is actually stripped of many characters, so a lot don't work. I have submitted a bug, so I hope this gets fixed.

 

EDIT: Looks like it is already being worked on http://bugs.matrix.squiz.net/view_bug.php?bug_id=6476


(Josh Sherwood) #6

Yes, thanks Nic. That bug submission is currently being worked on.

 

Once it is all sorted, the documentation will be revised to make more clear the scope of regex usage on the replace modifier, as well as including a few examples.


(Josh Sherwood) #7

The documentation has been updated here: http://manuals.matrix.squizsuite.net/keyword-replacements/chapters/keyword-modifiers.

 

Feel free to contact me should you have any further questions or suggestions. Thanks.


(Nic Hubbard) #8

The documentation has been updated here: http://manuals.matrix.squizsuite.net/keyword-replacements/chapters/keyword-modifiers.

 

Feel free to contact me should you have any further questions or suggestions. Thanks.

 

Thanks!


(Joel Porgand) #9

In the note you state "The following characters need to be escaped with a backslash: [ ] - ( )"

 

Isn't that self evident as it's a regex replace? If you're going to list metacharacters that need to be escaped in order to use as a plain character why not give a complete list instead of just those?


(Ashish Karelia) #10

In the note you state "The following characters need to be escaped with a backslash: [ ] - ( )"

 

 

Isn't that self evident as it's a regex replace? If you're going to list metacharacters that need to be escaped in order to use as a plain character why not give a complete list instead of just those?

 

A lot of meta character are already escaped by Matrix (by design in the legacy code). The one mentioned in the manuals are the ones that needs to be escaped by user and hence mentioned in the manuals.

 

 

Most of the regular character that would be used were tested to see if they needs to be escaped or not and then documented. 


(Joel Porgand) #11

I'm not clear what you mean.

 

Square braces seem to work as I would expect in a regex?

 

Additionally | (pipe) seems to just break things all over the place when I try to use it. Given it's a fairly important regex operator it might be nice to mention that it can't be used... (or if it can, how).