Let switch node regex mode optionally return matches#5387
Let switch node regex mode optionally return matches#5387
Conversation
|
Just to play devil's advocate on this; what's the risk with just doing this behaviour without adding another option for the user to think about? It will mean |
|
On second glance, I see this is adding 're' as a new option to the value type. As no existing flow will have that option in it today, then we could just define this as the behaviour without breaking existing flows. |
|
so not have it as an option ? It would potentially "pollute" some existing users msgs with the added .match property but I don't mind. It's also potentially slower, as we now do a global search to find all matches rather than trigger on first match. Shall I rework ? |
If I've read the PR right, I don't think it will as it relies on the user selecting the |
|
True - as long as you don't mind the possible performance hit (albeit small you would hope). |
and adds tests
Proposed changes
As per discussion https://discourse.nodered.org/t/switch-node-pass-on-regexp-matches-with-the-msg/99936 this PR adds an option to the regex condition of the switch node to allow it to return the matches and match groups. It doesn't change the default behaviour or any other modes.
This does of course change the message passing though (by adding msg.matches property) - which is unlike any other switch option - so may not be desired though it doesn't affect any other options. Other alternatives mean adding extra nodes to either redo the extraction of groups or using a function node.
And adds tests for new option.
Checklist
npm run testto verify the unit tests pass