extracting substring from a string

i am trying to get a substring using vbscript and not able to get it.

Here is the whole string/

varWI=  Work item W396364-01FEB18 created. I need to extract just the number W396364-01FEB18

using the below but it is not working

start=$$eval varWI.substring(varWI.indexOf("W"))

end = varWI.indexOf((" c"),start))

Number = varWI.substring(start,end)
sduser1Asked:
Who is Participating?
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.

CEHJCommented:
Why is this posted in Java please?
0
sduser1Author Commented:
I need help with the Java code. Not vbscript.
0
CEHJCommented:
OK, but can we first sort out whether it's Java or Javascript?
http://technojeeves.com/joomla/index.php/free/127-javascript-is-not-java
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

sduser1Author Commented:
Seems it is javascript. I need to extract W396364-01FEB18 from the below.

varWI=  Work item W396364-01FEB18 created.

 
 start=varWI.substring(varWI.indexOf("W"))

end = varWI.indexOf((" c"),start))

Number = varWI.substring(start,end)
0
Bill PrewCommented:
In that case try:

var varNumber = varWI.split(" ")[2];

Open in new window


»bp
0
Bill PrewCommented:
And a potentially more flexible way using a regular expression:

var varWI = "Work item W396364-01FEB18 created."; 
var varNumber = /W[0-9]+-[0-9]{2}[A-Z]{3}[0-9]{2}/.exec(varWI);

Open in new window


»bp
0
CEHJCommented:
Try

        var varWI = "Work item W396364-01FEB18 created."; 
        var reItem = /.* item ([\w\-]+) created.*/;
        varWI = varWI.replace(reItem, '$1');

Open in new window

0

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
leakim971PluritechnicianCommented:
var matches = varWI.match(/\s(W.+)/);

regex
0
leakim971PluritechnicianCommented:
var varWI = "Work item W396364-01FEB18 created.";
varWI = varWI.match(/\s(W.+)/)[1];

Open in new window

0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.