Regular expression to extract filename after a character and without extension

.netregex

I am looking for help in how to create a regular expression that extracts a substring from a string that looks like the following:

test123 #AMMA-TestFileName File's.xml

to…

AMMA-TEstFileName File's

Basically, removing the first "#" and everything before it. In addition, removing the ".xml" file extension.

Any help is appreciated as I am just getting started with regex. This is going to be used in a Nintex workflow action that supports the .NET regular expressions API.

Best Solution

The string you are looking for will be in the first group.

/#(.+?)\.xml$/

In C#

String extractFilename(String s) 
{
    Regex r = new Regex(@"#(?<filename>.+?)\.xml$", RegexOptions.Compiled);
    return r.Match(s).Result("${filename}"); 
}

edits: removed escaping the #, added end of line qualifier for extension, and added C# example