本文介绍了JavaScript正则表达式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些变量
var jdbcurl="jdbc:oracle:thin:%2F%2Finnova:1521%3BServiceName%3Dorcl%3BMaxPooledStatements%3D20%3BCatalogOptions%3D0%3BBatchPerformanceWorkaround%3Dtrue"
alert(jdbcurl.match(/:[\d]+/)); //gives me :1521
我怎样才能获得 jdbc:oracle:thin
, innova
, 1521
& orcl
jdbcurl
var?
How can I get jdbc:oracle:thin
, innova
, 1521
& orcl
out of jdbcurl
var?
更新
您可以在这里试用 (如果需要)
You can experiment here (if needed)
推荐答案
var jdbcurl="jdbc:oracle:thin:%2F%2Finnova:1521%3BServiceName%3Dorcl%3BMaxPooledStatements%3D20%3BCatalogOptions%3D0%3BBatchPerformanceWorkaround%3Dtrue"
var myregex = /([a-z:]+):%2F%2F([a-z]+):(\d+)%3BServiceName%3D([a-z]+)%3BMaxPooledStatements%3D20%3BCatalogOptions%3D0%3BBatchPerformanceWorkaround%3Dtrue/
var matches = myregex.exec(jdbcurl);
// jdbc:oracle:thin is in matches[1], innova is in matches[2], 1521 is in matches[3], and orcl is in matches[4]
这篇关于JavaScript正则表达式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!