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?

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

x
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?
sduser1Author Commented:
I need help with the Java code. Not vbscript.
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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)
Bill PrewIT / Software Engineering ConsultantCommented:
In that case try:

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

Open in new window


»bp
Bill PrewIT / Software Engineering ConsultantCommented:
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
CEHJCommented:
Try

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

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

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

Open in new window

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.