中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 17:55
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » [Question] Looking for a regex for file extensions
Printable Version  1,054 / 4
Floor1 electronixtar Posted 2006-05-23 17:44
铂金会员 Posts 2,672 Credits 7,493
Given a filename, I need to extract the file's extension, for example: test.htm, get htm. But what if there are multiple . ? For example test.2006.5.23.html, in the end I also need to get html. Please help, experts! Thanks!
Floor2 Climbing Posted 2006-05-23 18:38
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
What environment are you running in, classmate? What are the constraints?

Seems like there was already an example of this earlier.
Floor3 electronixtar Posted 2006-05-23 19:03
铂金会员 Posts 2,672 Credits 7,493
I'm talking about vbs
I think regexes are all basically universal, right?~~

My runtime environment:
WSH5.6,WinXP sp2
IE6+maxthon1.5.2
cmd.exe 5.1.2600.2180(xpsp_sp2_rtm.040803-2158)

p.s. I hope an expert can also give me a regex to get the part before the file extension~~ I'm really too dumb to write it myself! Thanks, thanks!
Floor4 无奈何 Posted 2006-05-23 19:29
荣誉版主 Posts 356 Credits 1,338
Brother electronixtar, I guess maybe you're overthinking it.
In regex, the expression will get the maximum match, and that happens to fit the requirement for an extension: the characters after the last “.” are the extension.
(.*)\.(.*)
\1 gets the filename.
\2 gets the extension.
Floor5 electronixtar Posted 2006-05-23 19:37
铂金会员 Posts 2,672 Credits 7,493
Heh~~~it really is

If you don't use regex for a long time, naturally you forget it completely~~~cramming hard now

[ Last edited by electronixtar on 2006-5-23 at 19:39 ]
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023