# CommandOutputParameter - regex

**URL:** <https://cwl.discourse.group/t/commandoutputparameter-regex/311>\
**Category:** CWL Questions\
**Created:** [February 15, 2021, 3:13am UTC](https://cwl.discourse.group/t/commandoutputparameter-regex/311 "2021-02-15T03:13:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Yue](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/nicholas_yue/32/95_2.png) [@Nicholas\_Yue](https://cwl.discourse.group/u/Nicholas_Yue)\
**Post date:** [February 15, 2021, 3:13am UTC](https://cwl.discourse.group/t/commandoutputparameter-regex/311/1 "2021-02-15T03:13:51Z")

</div>

Is there a way to perform regex in the output parameter processing

I have the following input string parameter  
‘/data1/nyue/projects/workflow-languages\_git/CWL/vfx/granular\_steps/python/output/test.$F4.exr’

which I’d out to do some regex magic to the following  
‘/data1/nyue/projects/workflow-languages\_git/CWL/vfx/granular\_steps/python/output/test.%04d.exr’

Is there a way to call regex ?

---

<div class="post-metadata">

**Author:** ![tetron](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/tetron/32/40_2.png) [@tetron](https://cwl.discourse.group/u/tetron)\
**Post date:** [February 15, 2021, 3:57pm UTC](https://cwl.discourse.group/t/commandoutputparameter-regex/311/2 "2021-02-15T15:57:22Z")

</div>

I’m not sure I understand, are you trying to rename the output file?

---

<div class="post-metadata">

**Author:** ![Nicholas\_Yue](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/nicholas_yue/32/95_2.png) [@Nicholas\_Yue](https://cwl.discourse.group/u/Nicholas_Yue)\
**Post date:** [February 15, 2021, 5:26pm UTC](https://cwl.discourse.group/t/commandoutputparameter-regex/311/3 "2021-02-15T17:26:30Z")

</div>

No, I am not trying to rename file.

The inputs are string and the output is another string.

I have two steps which uses different software, each of the software requires different convention for glob’bing files

I was hoping to use the first string with the $F4 and regex it to %04d, basically doing a

```auto
$F[1-9] -> %0[1-9]d

```

Hence I was wondering if there are any javascript/other-language-construct I can use for regex.

Otherwise, I am planning to add another step in the workflow just for doing the regex via Python or Go but that seems like heavy lifting for such a trivial task.

---

<div class="post-metadata">

**Author:** ![tetron](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/tetron/32/40_2.png) [@tetron](https://cwl.discourse.group/u/tetron)\
**Post date:** [February 15, 2021, 7:12pm UTC](https://cwl.discourse.group/t/commandoutputparameter-regex/311/4 "2021-02-15T19:12:32Z")

</div>

Oh, I think I understand now. You have a filename pattern, both pieces of software need to take that filename pattern, but the exact pattern formats are different.

Yes, you can certainly use a Javascript regex. Try something like this:

```auto
steps:
  step2:
    in:
      original_pattern: original_pattern
      pattern: {valueFrom: $(inputs.original_pattern.replace(/$F([1-9])/, '%d0$1d'))}

```

---

<div class="post-metadata">

**Author:** ![Nicholas\_Yue](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/nicholas_yue/32/95_2.png) [@Nicholas\_Yue](https://cwl.discourse.group/u/Nicholas_Yue)\
**Post date:** [February 16, 2021, 4:44am UTC](https://cwl.discourse.group/t/commandoutputparameter-regex/311/5 "2021-02-16T04:44:42Z")

</div>

I have figured out a solution.

Since I have a dependent step, I will generate the output sequence name in that step and use it in the ffmpeg step i.e. I do the regex in the previous step. So my render steps will output the sequence string with the %04d variation

My complete workflow for all the steps are now working.

Thank you @tetron

```auto
class: CommandLineTool
inputs:
- id: startFrame
  type: int
- id: endFrame
  type: int
- id: stepFrame
  type: int
- id: houdiniHIP
  type: string
- id: outputSequence
  type: string
outputs:
- id: renderedSequence
  type: string
  outputBinding:
    outputEval: ${ return (inputs.outputSequence.replace(/\$F([1-9])/, '%0$1d')) }
requirements:
- class: InlineJavascriptRequirement
baseCommand: henv
arguments:
- hrender
- -d
- mantra
- -e
- -f
- $(inputs.startFrame)
- $(inputs.endFrame)
- -i
- $(inputs.stepFrame)
- $(inputs.houdiniHIP)
- -o
- $(inputs.outputSequence)
successCodes:
- 0

```
