-5

I am new to regex and i want to extract strings from file path. Below is the mentioned filepath from which i want to extract string:

input : c://dev-dl-data-d2-us=east-1-5148727/all/stage/clinical/cro/raw/c/ca209_040/2018/08/02/aesae.csv

Output: ca209_040,aesae.csv
Shweta Sharma
  • 43
  • 1
  • 6

2 Answers2

0

Try this one, it matches either ca followed by one or more[0-9_] until it reaches / or the last word with .csv, you can insert comma( ,) after the match.

ca[0-9_]+|[a-z]+\.csv

demo here

The Scientific Method
  • 2,266
  • 2
  • 11
  • 23
0

One of possible solutions:

raw\/c\/(\w+).*\/([^\/]+)$

The fragments you want are the content of both capturing groups:

  • Group 1: A sequence of word chars after raw/c/.
  • Group 2: A sequence of chars between the last / and the end of string.

Note that the pattern for group 2 contains a sequence of chars other than /, so the preceding / matches just the last /.

Valdi_Bo
  • 27,886
  • 3
  • 21
  • 36