Ensuring string is at end of string/file

Tips on writing regular expressions for searching the post list

Moderators: Quade, dexter

Ensuring string is at end of string/file

Postby Vanguard » Mon Aug 11, 2003 1:55 pm

Say I have a filter expression of:

\.[hH][tT]([mM][lL]?)

because I need to be concerned whether the extension is lowercase, uppercase, or mixed case. Hopefully this expression covers filenames with an extension of:

.htm, .html

with the various permutations of capitalization. However, I want to ensure that this is at the end of the string/filename. I suspect that:

case 1: \.[hH][tT]([mM][lL]?)$

won't work because maybe it just looks for "m" and "ml" (and their permutations of capitalization) at the end of the string/filename and not the whole string at the end of the string/filename. Would I have to instead use:

case 2: (\.[hH][tT]([mM][lL]?))$

But then maybe case 1 would work since all the characters must be contiguous. To simplify and not bother about case sensitivity, would:

\.ht(ml?)$

work or would I need to use:

(\.ht(ml?))$

to guarantee .htm or .html was at the very end of the string/filename?
Vanguard
n00b
n00b
 
Posts: 4
Joined: Tue Jul 01, 2003 10:15 am

Postby Smite » Mon Aug 11, 2003 2:52 pm

$ isn't a modifier for other parts of the string, so being placed after brackets or just characters shouldn't make any difference.
User avatar
Smite
Katamari Damacy Addict
 
Posts: 5318
Joined: Sat May 19, 2001 1:54 am
Location: Alberta, Canada

Registered Newsbin User since: 03/27/03


Return to Regular Expressions

Who is online

Users browsing this forum: No registered users and 2 guests