Using Regex to filter Get files from Folder

I am trying to use Regex to select only a single target file at a time inside a loop. I want to use the loop variable ${element} plus " - update" as the matching pattern. I can’t find any real documentation or examples for the Regex syntax to use. Question 1: does the Regex only apply to the filename or full path? Question 2: can I use the variable name etc directly in the GetFiles config or do I need to build a Regex variable (string), construct it separately, then use only the Regex variable in the GetFiles RegEx spot? I have tried things like:

\b${element} - update\b
\b${element}\s±\s+update\b

and so on…any help much appreciated. thanks, Tom

1 Like

Hi @thomasfountain

The regex is applied only to the name of the file, not the whole path.

If you need to use a variable in the regex, you need to build the regex separately using Constant value action and save in a string variable, and then use the variable int he regex field. You can see an example in this post:

There are several resources with Regex syntax rules. Here are some of them:
https://www.rexegg.com/regex-quickstart.html
https://docs.pexip.com/admin/regex_reference.htm

I also use online regex validators to check if the regex is correct. For example, this one https://regex101.com/

I believe, in your case you will need to use something like .*${element}.*update.* in the Constant value action.

I hope it helps!:slightly_smiling_face:

Thank you! Your suggestion worked perfectly and I super appreciate the guidance. Where would I have found documentation that said you can’t use a variable in the RegEx line of Get Folder contents (just so I know)?

My Get Folder contents now returns the full path of the proper file from the list of files in the folder.

However…When I use that string variable in a Launch application command line it appears that the spaces in the file name confuse the Launch and it appears it is trying to launch the first part of the file name then separately the rest of the file name. Do I need to add "'s or something on each end of the filename string variable to prevent that?

Again, many thanks for awesome response and support!

I don’t think we specify it in the documentation. We’ll add it.

Is it an excel file you are trying to open?

It is a .CSV but I solved that by putting "'s on front and back end of the filename variable content before using that variable in the command line launch. So all good with launching.

Since you are being super helpful my very last question (for today anyway :wink: is I open the CSV, specify a range, use Ctrl+C to grab it, use Clipboard to store that copied range into a table variable then later try to use SetRange in Excel to paste those values into an Excel. It appears that the end of row delimiter is confused because the second row of cells starts getting appended to last cell in first row. Is my general approach sound and what might be going on? Is there a better way and is there a way to specify the SetRange to store numbers as numbers not strings? thanks again, Tom

Thanks again, I got everything working. I switched the row delimiter to Linux/MaxOS and magically fixed those Clipboard > table variable issues. Then I wasn’t using right index syntax to grab a specific value from a table but finally found it as table_name.get(x,y) I had assumed list like meaning table-name[x,y]. All set with today’s needs thanks again you have been super helpful!

Regards and enjoy your weekend. Thanks, Tom

1 Like

@thomasfountain sorry I couldn’t answer earlier.
Yes, in most cases the default separator in the clipboard is Linux/MaxOS line break.

Glad you made it work :slightly_smiling_face:

Hi ashapkina
i am trying to get the file name from the path using regex.
My file path will be stored in an list while using get folder contents.Now i want to apply regex pttern to that file path stored in a list inorder to get file name.
For example:${element_list} is where i store the file path which is inside the for each loop.
Now how can i apply regex to ${element_list} every time inside the for each loop?

Thanks in advance

Try using this custom script to get the filename from the path https://kb.workfusion.com/display/RPAe/Code+Samples#CodeSamples-GettingfilenamefrompathBlueCommunity

i used substring for the same.
thanks for your response Ashapkina :slightly_smiling_face:

1 Like

Hi thomasfountain,
Can you share how you use regex in the script ?