#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    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.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,960
    Rep Power
    9397
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0
    Thank you requinix, that worked perfectly.

IMN logo majestic logo threadwatch logo seochat tools logo