Search code examples
.netregexnintex-workflow

RegEx: REPLACE REGEX to remove first character and everything after the last _


I have this RegEx which Extracts word after removing the first letter a and everything after the last underscore "_". I need to a same output but for "Replace" RegEx.

Input: asome test file-2_rev2.docx
RegEx: (?<=^a).+?(?=_.+?$)
Result: some test file-2

The code above works but an Extract. I need to be able to use a REPLACE RegEx. Basically the extract Regex put the result into a collection variable and I have to 5 more lines of code to get the value. The replace RegEx must be one liner like I posted. Any suggestion?

I tried below but i need to combine this into one

(^.*?(?=a)a)|[^_]+$

This (^.*?(?=a)a)|[^_]+$ gives me the file name but not removing the last underscore


Solution

  • Here is the final REPLACE REGEX (NINTEX)

    Pattern:  (^.*?(?=a)a)|[_].*$
    Input Text: asome test file-2_rev3.dotx
    Results: some test file-2