February 11th, 2013, 07:10 PM
-
Help removing file extension from this regex
Hi, I'm fairly new to regular expressions but I was able to put together most of what I need, just having a problem trying to figure out how to capture everything between the two round brackets minus the .txt extension. This is what I have so far:
#\/Type \/Filespec[\n]\/F \((.*?)\)#
I'm trying to use that regex on this data:
/Type /Filespec
/F (file_name.txt)
Trying to capture just, file_name, but it's giving me file_name.txt right now. I've tried this regex as well but no luck when using it with preg_match:
#\/Type \/Filespec[\n]\/F \((.*?)\).txt#
I would appreciate any help with this.
February 11th, 2013, 07:26 PM
-
That would work for "/F (file_name).txt".
Move the ".txt" one spot earlier. And escape the period so it's not a metacharacter.
Code:
#\/Type \/Filespec[\n]\/F \((.*?)\.txt\)#
Last edited by requinix; February 11th, 2013 at 07:28 PM.
February 11th, 2013, 08:59 PM
-
Thank you requinix, that worked perfectly.