Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

regex advice - match name of the html file

Last post 07-15-2008, 9:54 PM by jeff.hillman. 3 replies.
Sort Posts: Previous Next
  •  07-15-2008, 3:34 AM 44143

    regex advice - match name of the html file

    Hi,

    can anybody help me with regex to match this:

    http://www.google.com/level1/name.html

    so something like match all between last ocurance of "/" and ".html"

     

    Thanks in advance,

    Cash

    p.s. sorry on noob question :)

    Filed under: ,
  •  07-15-2008, 6:20 AM 44148 in reply to 44143

    Re: regex advice - match name of the html file

    Cash,

    This should do the trick, assuming the language/library you are using supports look-ahead:

    [^/]+(?=\.html)

     

    Jeff

     

  •  07-15-2008, 6:51 AM 44149 in reply to 44148

    Re: regex advice - match name of the html file

    Thank you very much Jeff!! My current regex in web.config (.net) rule is: "~/hardcodeddirectory/(.*).htm" with that rule I am matching name of html file Only, I forgot one problem.. :( As i should have web structure in few depth levels, this is to simple regex form me.. So i will have urls structured like this: domainname.com/level1.html domainname.com/level1/level2.html domainname.com/level1/level2/level3.html depending on level variable page will work on different way, so, i have to make 3 regular expressions rules for those 3 cases, and this first one will match all of that what isn't good.. :( Please help, I will buy you virtual beer :) Thanks in advance, Cash
  •  07-15-2008, 9:54 PM 44166 in reply to 44149

    Re: regex advice - match name of the html file

    Cash,

    I'm not sure I completely understand your problem, but I'll give it a shot:

    Depth of 1:

    (?<=^[^/]+/)[^/]+(?=\.html)

     

    Depth of 2:

    (?<=^([^/]+/){2})[^/]+(?=\.html)

     

    Depth of 3:

    (?<=^([^/]+/){3})[^/]+(?=\.html)

     

    Like the original expression I gave you, these expressions will just match the name of the HTML file.

     

    Jeff

     

View as RSS news feed in XML