Is it possible to use regular expressions in a function node?

I have the next code:

let validationRangeOfDates = valueOfCurrentItem.match(/(\d{1,4}([.\-/])\d{1,2}([.\-/])\d{1,4})/g);

Being valueOfCurrentItem a string with values as “Ok 10/01/2022 to 14/10/2022”

I use this regular expresion to recover the dates from the string to an array.
The error is the next:

TypeError: valueOfCurrentItem.match is not a function
    at C:\Users\Interacso\AppData\Local\Programs\n8n\resources\app\node_modules\n8n-nodes-base\dist\nodes\Function:27:38
    at Object.<anonymous> (C:\Users\Interacso\AppData\Local\Programs\n8n\resources\app\node_modules\n8n-nodes-base\dist\nodes\Function:70:2)
    at (C:\Users\Interacso\AppData\Local\Programs\n8n\resources\app\node_modules\vm2\lib\main.js:1233:29)
    at Object.execute (C:\Users\Interacso\AppData\Local\Programs\n8n\resources\app\node_modules\n8n-nodes-base\dist\nodes\Function\Function.node.js:95:31)
    at Workflow.runNode (C:\Users\Interacso\AppData\Local\Programs\n8n\resources\app\node_modules\n8n-workflow\dist\src\Workflow.js:524:37)
    at C:\Users\Interacso\AppData\Local\Programs\n8n\resources\app\node_modules\n8n-core\dist\src\WorkflowExecute.js:447:62

Is it possible to use regular expressions in a function node?

Thank you very much for your time!

Hey @franchogarcia, I gave this a quick go on my end, but did not run into the problem you have described:


I’ve attached my example workflow below for reference:

Example Workflow

Is there a chance valueOfCurrentItem might not be the expected string for some of the items you’re processing?

Hello MuteJam!
First at all, thank you very much for your quick answer.
Regarding to your question, perhaps you are right and some value might not be the expected string. I am using the desktop version and yet I have not idea about how copy/paste workflows there and debug the source code of functions node. Normally with something as console.log would be enough jejeje
Could you recommend me how I can debug or to use console.log in desktop n8n version?

Again thank you very much for your time.

Hey @franchogarcia, as for copying and pasting the workflow you should be able to simply copy the workflow’s JSON code here from the forum and paste it into your n8n canvas using Ctrl+V.

As for debugging: console.log() is also my preferred way of doing this :smile:. To avail of this functionality, you can open the browser console right in the desktop app using the respective keyboard combination (Ctrl+Shift+I on Windows):

If that doesn’t work for any reason you can also access http://localhost:5679 in a browser of your choice and open the UI in there. The username and password required can be viewed via the desktop app’s Auth menu:

1 Like

Good morning @MutedJam!!
Thank you very much for your time and support!! Your solutions have been very usefull!!
Thanks a lot!!
I am starting to love n8n!


1 Like

Nice, glad to hear this worked for you!

1 Like