Hello everyone,
I am having trouble what function to use.
What I am trying to achieve is I have a file name that says NEW_210917. I also have a list NEW_TXT_210917, RNW_TXT_TXT_210917, RPL_TXT_210917 and NEW_TXT_TXT_210917.
Regardless of the file names on the list. I need to return the list that has NEW and 210917 on their names.
So based on the given above. My result should be NEW_TXT_210917 and NEW_TXT_TXT_210917.
Any help will be appreciated. Thank you.
Discussion posts and replies are publicly visible
Hi,
Using a regular expression would be a good way to accomplish this, like in the following snippet:
a!localVariables( local!test: { "NEW_TXT_210917", "RNW_TXT_TXT_210917", "RPL_TXT_210917", "NEW_TXT_TXT_210917" }, a!forEach( items: local!test, expression: if( regexmatch("(NEW)(.*)(210917)", fv!item), fv!item, {} ) ) )
I am guessing that probably you don't want to search specifically for "210917", but instead for a given date, and you could also search for the remaining text in a case sensitive way, but you can modify the regular expression string in order to accomplish that if needed.
This would require the Regular Expressions functions plugin: community.appian.com/.../regular-expression-functions
Wow Marco Amador this actually works. Although, I tried some tweeks because I need "NEW" to be flexible because there are file names such as RNW_210917. But this should be good.
a!localVariables( local!fileName: left(ri!fileName, 3), local!filesInSftp: ri!filesSftp, local!filesToDump: a!forEach( items: local!filesInSftp, expression: if( regexmatch(concat(local!fileName,"(.*)",datetext(today(), "YYMMdd")), fv!item), fv!item, {} ) ), local!filesToDump )
One more question, will the pattern ("(NEW)(.*)(210917)", fv!item) still applies in case that I will have a file name such as NEW_TXT_200917_TXT_TXT or NEW_210917? Thank you.
Hi Sarah,
Yes, it would, because if you 'decompose' the regular expression:
(NEW) - we are looking for this particular bit (all uppercase) to happen 1 time in the text
(.*) - then any character, happening 0 or more times
(210917) - then this particular sequence, happening 1 time
Since these conditions are verified in both the cases you provided (providing you fix the date in the first case to be 21 instead of 20), it would work.
I highly recommend this website to test your regular expressions and learn more about them - https://regexr.com/