String Manipulation with JS

Hi Experts,

Can anyone tell me how to search for end extract string paths of a string using JavaScript?

For example, say you have a string like ABC{23}, I want to extract this as "ABC" as str1 and "23" as str2. Here is my pseudo-code for this:

pos = strpos(str0, "{")
str1 = substr(str0, 0, pos) //get everything until "{"

str0 = substr(str0, pos+1) //get everything after "{"
pos = strpos(str0, "}"
str2 = substr(str0, 0, pos) //get everything until "}"

Any help will be appreciated.
APD TorontoSoftware DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
One approach, using the substring function:

var source = 'ABC{23}';

var openBraceIndex = source.indexOf('{');
var closeBraceIndex = source.indexOf('}', openBraceIndex + 1);
var str1 = source.substring(0, openBraceIndex);
var str2 = source.substring(openBraceIndex + 1, closeBraceIndex);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rainer JeschorCommented:
and an alternative way would be using Javascript and regular expressions:
var source = "ABC{23}";
var myRegexp = /(\w*)\{(\w*)\}/g;
var match = myRegexp.exec(source);
alert(match[1]);  // ABC
alert(match[2]);  // 23

Open in new window

Pravin AsarPrincipal Systems EngineerCommented:
No points please, as I not not posting answer to your question.

But bookmark this link about split function. Really nice reference and examples
APD TorontoSoftware DeveloperAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.