CommandOutputParameter - regex

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 ?

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

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

$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.

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:

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

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

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