-
Notifications
You must be signed in to change notification settings - Fork 508
Add regex switch expression tool #7314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bernt-matthias
merged 11 commits into
galaxyproject:main
from
npinter:add-regex-switch-expression-tool
Oct 9, 2025
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0285823
Initial commit
npinter edf2b1e
Change test input name
npinter 915c1e0
Fix linting
npinter c220d1f
Push
npinter 4199ec9
Fix linting
npinter 7851c28
Fix linting
npinter e2e5097
Fix linting
npinter 767e9f5
Fix tests
npinter 2da8ced
Update repository URLs to main branch
npinter e4dfb0c
Refactor regex matching logic and add link for regex syntax to help
npinter 64f78fe
Test
npinter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| categories: | ||
| - Text Manipulation | ||
| description: Regex switch | ||
| long_description: | | ||
| Regex switch outputs a boolean from regex on element identifier. | ||
| name: regex_switch | ||
| owner: iuc | ||
| remote_repository_url: https://github.com/galaxyproject/tools-iuc/tree/master/tools/regex_switch | ||
| homepage_url: https://github.com/galaxyproject/tools-iuc/tree/master/tools/regex_switch | ||
| type: unrestricted | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <tool name="Regex switch" id="regex_switch" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" tool_type="expression"> | ||
| <description>boolean from regex on element identifier</description> | ||
| <macros> | ||
| <token name="@TOOL_VERSION@">1.0.0</token> | ||
| <token name="@VERSION_SUFFIX@">0</token> | ||
| </macros> | ||
| <expression type="ecma5.1"><![CDATA[{ | ||
| var name = $job.input.name; | ||
|
bernt-matthias marked this conversation as resolved.
|
||
| var pat = $job.pattern; | ||
| var matched = false; | ||
|
|
||
| try { | ||
| if (pat !== "") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Added! |
||
| var re = new RegExp(pat); | ||
| matched = re.test(name); | ||
|
bernt-matthias marked this conversation as resolved.
Outdated
|
||
| } | ||
| } catch (e) { | ||
| return { "__error_message": "Invalid regular expression: " + (e && e.message ? e.message : String(e)) }; | ||
| } | ||
|
|
||
| return { "matched": matched, "unmatched": !matched }; | ||
| }]]></expression> | ||
| <inputs> | ||
| <param name="input" type="data" format="data" | ||
| label="Dataset" /> | ||
| <param name="pattern" sanitize="false" type="text" label="Regex pattern" | ||
| help="Example: \.csv$"> | ||
| <sanitizer> | ||
| <valid> | ||
| <add preset="string.printable"/> | ||
| </valid> | ||
| </sanitizer> | ||
| </param> | ||
| </inputs> | ||
| <outputs> | ||
| <output type="boolean" name="matched" from="matched" label="Match result"/> | ||
| <output type="boolean" name="unmatched" from="unmatched" label="Unmatched result"/> | ||
| </outputs> | ||
| <tests> | ||
| <test expect_num_outputs="2"> | ||
| <param name="input" value="sample.csv" ftype="txt"/> | ||
| <param name="pattern" value="\.csv$"/> | ||
| <output name="matched" value_json="true"/> | ||
| <output name="unmatched" value_json="false"/> | ||
| </test> | ||
|
|
||
| <test expect_num_outputs="2"> | ||
| <param name="input" value="table.tsv" ftype="txt"/> | ||
| <param name="pattern" value="\.csv$"/> | ||
| <output name="matched" value_json="false"/> | ||
| <output name="unmatched" value_json="true"/> | ||
| </test> | ||
| </tests> | ||
| <help><![CDATA[ | ||
| **Regex switch** | ||
|
|
||
| Matches a regular expression against the name of the input file. It emits two booleans: | ||
|
bernt-matthias marked this conversation as resolved.
|
||
| `matched` (the match result) and `unmatched` (its negation). Connect either to a step's **Conditionally skip step?** input. | ||
| ]]></help> | ||
| </tool> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| col1,col2 | ||
| 1,2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| col1 col2 | ||
| 1 2 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.