[英]Regex help match everything after given word which ends with some file extension
I want to be able to match every string which contains "assets" and has a given extension ending - lets say png, jpeg, json.我希望能够匹配包含“资产”并具有给定扩展名结尾的每个字符串 - 比如说 png、jpeg、json。
Those are the cases I could think of and currently, the regex I was able to come with is handling only the first three.这些是我能想到的情况,目前,我能够使用的正则表达式只处理前三个。
Those are the strings I test against -这些是我测试的字符串 -
./assets/example.js
./assets/recursive-directory/example/exampleTwo.json
../assets/recursive-directory/example/exampleThree.json
../../../assets/recursive-directory/example/exampleThree.json
C:\Users\user1\project\assets\game-assets\translates.json
And here is my current regex -这是我目前的正则表达式 -
\.*\/assets\/.*\.(png|jpe?g|gif|json|js)$
If you want to match either slashes or backslashes, you need to say so.如果要匹配斜杠或反斜杠,则需要这样说。
[\\/]assets[\\/].*\.(png|jpe?g|gif|js(on)?)$
The leading \.*
wasn't contributing anything useful, so I took it out.领先的
\.*
没有贡献任何有用的东西,所以我把它拿出来了。
In Javascript, you'll need to backslash-escape the literal backslash, even in a character class.在 Javascript 中,您需要对文字反斜杠进行反斜杠转义,即使在字符 class 中也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.