regex - Match last dir before filename in unix path -
i need find regex extract last dir before file in full path strings these:
./resources/views/product/edit.html.twig ./resources/views/product/show.html.twig ./resources/views/product/new.html.twig
so these strings yield 'product'.
you may use
([^/]+)/[^/]*$
see a demo on regex101.com.
broken apart, says:
([^/]+) # capture not /, @ least once / # / [^/]* # 0+ not / $ # end of line
depending on actual language and/or delimiters used, may need escape forward slashes \/
.
Comments
Post a Comment