China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 16:51
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Question] Looking for a regex for file extensions View 973 Replies 4
Original Poster Posted 2006-05-23 17:44 ·  中国 四川 成都 联通
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
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!

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 2 Posted 2006-05-23 18:38 ·  中国 浙江 杭州 电信
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
What environment are you running in, classmate? What are the constraints?

Seems like there was already an example of this earlier.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2006-05-23 19:03 ·  IANA 局域网IP(Private-Use)
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
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!

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 4 Posted 2006-05-23 19:29 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
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.
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 5 Posted 2006-05-23 19:37 ·  IANA 局域网IP(Private-Use)
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
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 ]

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Forum Jump: