Mercurial > repos > iuc > regex_switch
changeset 0:8da8330208f4 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/regex_switch commit 502f06ff9cb9edd0eceaba726b2cc848757e34dd
| author | iuc |
|---|---|
| date | Thu, 09 Oct 2025 08:39:02 +0000 |
| parents | |
| children | |
| files | regex_switch.xml test-data/sample.csv test-data/table.tsv |
| diffstat | 3 files changed, 65 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regex_switch.xml Thu Oct 09 08:39:02 2025 +0000 @@ -0,0 +1,61 @@ +<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; + var pat = $job.pattern; + var matched = false; + + try { + var re = new RegExp(pat); + matched = re.test(name); + } 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> + <validator type="empty_field" message="Please enter a regular expression."/> + </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: +`matched` (the match result) and `unmatched` (its negation). Connect either to a step's **Conditionally skip step?** input. + +**Regex syntax reference:** https://262.ecma-international.org/16.0/index.html#sec-patterns +]]></help> +</tool>
