Question

REGEX support

  • 19 October 2023
  • 4 replies
  • 3 views

Badge +11

Hi

 

can you help me to find the correct regex to extract only the string in bold (ALESSANO)

 

\\\\199.168.30.208\\dati\\pippo\\PUGLIA\\ALESSANO\\INGRESSO\\ALESSANO\\tracciato unico.shp

 

thx

 

Francesco


4 replies

Badge +7

You can use stackoverflow for this. Also do you just want ALESSANO or du you always want the value between the second to last \\ and the last \\.

Also can't you just use the FilenamePartExtractor transformer for this kind of stuff.

Userlevel 3
Badge +25

If you want the directory the shapefile resides in, I would consider using the FilenamePartExtractor. Passing that string will result in a _dirname attribute.

image

Userlevel 3

I would skip using a regex for this, simply for the reason that it gets a bit unmaintainable unless you're already familiar with it. The FilenamePartExtractor is my preferred solution.

For fun, you could also simply use an AttributeSplitter followed by a ListIndexer. This has the added bonus of giving direct access to all the individual folder names:

image

Userlevel 1
Badge +16

Hi @checcosisani​ , I agree that FilenamePartExtractor is a better solution in this case, but if you would like to know a regular expression to extract the interest part anyway, try this regex with StringSearcher.

(?<=\\)[^\\]+(?=\\[^\\]+$)

 

Reply