Reputation: 12347
I have some variable
var jdbcurl="jdbc:oracle:thin:%2F%2Finnova:1521%3BServiceName%3Dorcl%3BMaxPooledStatements%3D20%3BCatalogOptions%3D0%3BBatchPerformanceWorkaround%3Dtrue"
alert(jdbcurl.match(/:[\d]+/)); //gives me :1521
How can I get jdbc:oracle:thin
, innova
, 1521
& orcl
out of jdbcurl
var?
Update
You can experiment here (if needed)
Upvotes: 3
Views: 14750
Reputation: 5963
Use decodeURIComponent() first, then split on semicolons. Don't make it hard on yourself!
Upvotes: 0
Reputation: 99
you could also try this for better url readability during regexp maintenance if you have to parse several urls:
var jdburl = unescape("jdbc:oracle:thin:%2F%2Finnova:1521%3BServiceName%3Dorcl%3BMaxPooledStatements%3D20%3BCatalogOptions%3D0%3BBatchPerformanceWorkaround%3Dtrue");
var myRegExp = new Regexp('([a-z:]+)://(\\w+):(\\d+);ServiceName=(\\w+);');
var matches = myRegExp.exec(jdburl);
Upvotes: 5
Reputation: 8455
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]
Upvotes: 10
Reputation: 13877
I'd say jdbcurl.split(/(%..)/)
would be a start - and then you could check the elements on whether to keep them or split them even further.
Upvotes: 0