开发者

Regex: how do I capture the file extension?

How do I determine the file extension of a file name strin开发者_JAVA百科g?

lets say I have

I'm.a.file.name.tXt

the regex should return tXt


something like \.[^.]*$ should do it


You probably don't need regex - most languages will have the equivalent to this:

ListLast(Filename,'.')

(If you do need regex for some reason, Scharron's answer is correct.)


What language is this in? It's quite possible you don't want to actually use a regex - assuming the name is a String you'll probably just want to do something like split it over periods and then choose the last segment. Okay, that's sort of a regex answer, but not a proper one.


/^(.*?)\.(.*)$/

The '?' makes it greedy. Your result will be in the second group.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜