Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE (PHP <7.3)

/
(?<FileNameWithoutExtension>\w+)(\.\w+)?[^\/]*$
/
mg

Description

If given a linux file path match the filename without the extension. It extracts FileNameWithoutExtension into its own match group so that you can use it in things like Logstash Grok.

Submitted by Chris Magnuson, by combining other peoples starting points - 9 years ago