Question

REGEX support

  • 19 October 2023
  • 4 replies
  • 8 views

Userlevel 1
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

Userlevel 3
Badge +12

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 +27

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 5

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 3
Badge +17

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