3

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)

4 Answers 4

10
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]
Sign up to request clarification or add additional context in comments.

Comments

5

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);

2 Comments

I think this is a nicer solution than mine. Why do you have double backslashes for \\w and \\d ?
It's a string, not a regexp literal, so you need the extra backslashes.
0

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.

Comments

0

Use decodeURIComponent() first, then split on semicolons. Don't make it hard on yourself!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.