简体   繁体   English

使用正则表达式的Grep文件扩展名

[英]Grep file extension using regular expression

I have filenames for examples as below names 我有以下示例的文件名

1) "Wireshark-win64-1.12.5.exe" 2) "Service - Document.docx" 1)“ Wireshark-win64-1.12.5.exe” 2)“服务-Document.docx”

Is there anyway I can grep the file extension using some generic regular expression and save it in a xslt variable. 无论如何,我可以使用一些常规正则表达式grep文件扩展名并将其保存在xslt变量中。 I was using some string function as below, but for value such as shown above in 1), it won't work. 我正在使用以下字符串函数,但是对于上面1)中所示的值,它将无法正常工作。

<xsl:variable name="fileExtension" select="substring-before(substring-after($filename,'.'),'&quot;')"/>

If you're using XSLT 2.0, then: 如果您使用的是XSLT 2.0,则:

tokenize($filename, '\.')[last()]

will extract the file extension from $filename for you. 将为您从$ filename中提取文件扩展

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM