[英]Regular expression issue when match a string in javascript
I am very, very n00b in regular expression, I'm trying to learn but no success :). 我在正则表达式中非常非常n00b ,我正在尝试学习但没有成功:)。
So I have the following file name: myFile.8.9.6-x64.txt
or myFile.8.9.6-x86.txt
因此,我具有以下文件名:
myFile.8.9.6-x64.txt
或myFile.8.9.6-x86.txt
So, I want to create a regular expression in order to match x64
or x86
string in file name with: 因此,我想创建一个正则表达式,以便将文件名中的
x64
或x86
字符串与以下内容匹配:
var regexp = new RegExp(/[x_X][8][6]|[x][6][4]$/);
console.log(regexp.test("myFile.8.9.6-x64.txt")); //returns false instead of true
So, where is my mistake ? 那么,我的错误在哪里?
You can actually use this regex: 您实际上可以使用此正则表达式:
var regexp = /x(?:86|64)\./i;
new RegExp
takes a string actually not a regex with delimiters as shown in your question new RegExp
接受的字符串实际上不是带分隔符的正则表达式,如您的问题所示 $
after 64/86
but your file names are not ending with 64/86
. 64/86
之后有$
,但是文件名不是以64/86
结尾。 x
x
/i
for ignore case matching /i
忽略大小写匹配
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.