-1

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

24K Gold
  • 41
  • 1
  • 2
  • 10
  • Thanks for flagging negatively. It made me go out of way and come up with my own to get the solution. – 24K Gold Feb 16 '18 at 14:24

1 Answers1

0

Here is the final REPLACE REGEX (NINTEX)

Pattern:  (^.*?(?=a)a)|[_].*$
Input Text: asome test file-2_rev3.dotx
Results: some test file-2
24K Gold
  • 41
  • 1
  • 2
  • 10
  • Sorry, but this regex is not equivalent to the matching regex you posted. Note that `(?=a)a` is equal to `a` and `.*?` before `a` also matches any text there is at the start of the string before `a` (your requirement was to match `a` at the start of the string). – Wiktor Stribiżew Feb 16 '18 at 14:16
  • Sorry Wiktor for not being articulate the issue. Basically, i needed a replace regex to get rid of first letter "a" and everything after an underscore "_". Thanks for all your help. I appreciate it. – 24K Gold Feb 16 '18 at 14:23
  • It's cool. lets leave the post as is. I am okay with Negative flags. It helps me improve my post. – 24K Gold Feb 16 '18 at 14:34
  • 1
    If you want to improve the answer, check my top comment. Also, you may check the http://regex101.com site, paste your pattern there and adjust as you see fit. Also, it would be a good idea to create a demo for your solution there. – Wiktor Stribiżew Feb 16 '18 at 14:38