我是Javascript中正则表达式的新手.
字符串看起来像
Password=6)8+Ea:4n+DMtJc:W+*0>(-Y517;Persist Security Info=False;User ID=AppleTurnover;Initial Catalog=ProductDB;Data Source=Sydney
我试图从中提取这一点
Password=6)8+Ea:4n+DMtJc:W+*0>(-Y517
从字符串.
所以我有:
string="`Password=6)8+Ea:4n+DMtJc:W+*0>(-Y517;Persist Security Info=False;User ID=AppleTurnover;Initial Catalog=ProductDB;Data Source=Sydney" substring=string.match('/Password=(.*);/g');
它再次返回整个字符串.这里出了什么问题?
正则表达式不应该用引号括起来.使用[^;]+
选择任何东西,直到;
.
var password = string.match(/Password=([^;]+)/)[1];
string = "`Password=6)8+Ea:4n+DMtJc:W+*0>(-Y517;Persist Security Info=False;User ID=AppleTurnover;Initial Catalog=ProductDB;Data Source=Sydney";
var password = string.match(/Password=([^;]+)/)[1];
document.write(password);