开发者

Actionscript: Regular expression for file type checking

开发者 https://www.devze.com 2023-01-21 16:43 出处:网络
I want to check the file extension from the string using regular expression in action script. By googling, I find this, but I\'m week t开发者_开发知识库o regular expression.

I want to check the file extension from the string using regular expression in action script.

By googling, I find this, but I'm week t开发者_开发知识库o regular expression.

Thanks.


This regex is more reliable than the given example:

  ^[^\\?\/%*:|"><]+\.([^\\?\/%*:|"><]*)$

You can refer to the file extension as $1 if you refer to it in replacement part.

You can refer to the file extension as \1 if you refer to it in search part.

Explanation

  • ^ Assert position at the beginning of a line.
  • [^\\?\/%*:|"><]+\. Matches any character except \, ?, /, %, *, :, |, ", >, <, at least one character, until the last . character.
  • ([^\\?\/%*:|"><]*) Matches any character except \, ?, /, %, *, :, |, ", >, <, as many as possible or none, and capture the bracketed part as group number 1.
  • $ Assert position at the end of a line.
0

精彩评论

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