Skip to content

Let switch node regex mode optionally return matches#5387

Open
dceejay wants to merge 3 commits intodevfrom
add-switch-regex-option-to-return-matches
Open

Let switch node regex mode optionally return matches#5387
dceejay wants to merge 3 commits intodevfrom
add-switch-regex-option-to-return-matches

Conversation

@dceejay
Copy link
Member

@dceejay dceejay commented Dec 13, 2025

and adds tests

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

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

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@knolleary
Copy link
Member

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 msg.match is set - but we could only set that if there are matching groups.

@knolleary
Copy link
Member

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.

@dceejay
Copy link
Member Author

dceejay commented Jan 21, 2026

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 ?

@knolleary
Copy link
Member

It would potentially "pollute" some existing users msgs with the added .match property but I don't mind.

If I've read the PR right, I don't think it will as it relies on the user selecting the re type for the value - an option that wasn't available until this PR?

@dceejay
Copy link
Member Author

dceejay commented Jan 22, 2026

True - as long as you don't mind the possible performance hit (albeit small you would hope).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants