I could use a little help with a RegEx expression.
I a Switch flow we are renaming files by using the e-mail subject attached to the file. The subject may contain characters like !^<>\ which are considered illegal characters to be used in a filename.
I want af RegEx to sort out everything but these characters, put this in Private data and then use this Private Data information to rename the files.
I'm using this RegEx: [^(?!.*:^<>)]
Testet on regex101.com this will do this T*e:s<t = Test
However, when used in Switch it seem to only return the first character, so T*e:s<t = T
Any ideas?
RegEx
Re: RegEx
If you test it on regex101.com, then on the right you can see your Match information. This shows that the first match is "T", the second match is "e", and so on:
I assume you are using the "Search" string manipulation in Switch? This will always only return the first match it finds, which is why you only get "T".
I'm afraid the only option I see is a script. Something like this:
This will get all the matches in a string array and then join the string array together.
I assume you are using the "Search" string manipulation in Switch? This will always only return the first match it finds, which is why you only get "T".
I'm afraid the only option I see is a script. Something like this:
Code: Select all
//var input = job.getVariableAsString("[Email.Subject]");
var input = "T*e:s<t";
var regExp = /[^(?!.*:^<>)]/g;
var result = input.match(regExp);
result.join("");
Re: RegEx
Hi Padawan,
You are absolutely right. I'm trying to use the "Search" string manipulation in Switch and it only returns the first match.
However, your script works perfect! I can use that with a Rename element and this way I don't even have to bother putting stuff into Private data or anything.
Thanks a lot!
You are absolutely right. I'm trying to use the "Search" string manipulation in Switch and it only returns the first match.
However, your script works perfect! I can use that with a Rename element and this way I don't even have to bother putting stuff into Private data or anything.
Thanks a lot!
Re: RegEx
By the way. Is there any way to search for a quotation mark (") as well?
Re: RegEx
You're welcome. And yes you can, you just need to escape the " with a \ in the regex:
Code: Select all
//var input = job.getVariableAsString("[Email.Subject]");
var input = "T\"\'*e:s<t";
var regExp = /[^(\"?\'!.*:^<>)]/g;
var result = input.match(regExp);
result.join("");
Re: RegEx
Great, Padawan! Thanks again