views:

45

answers:

2

I have the following string:

[assembly: AssemblyVersion("1.0.0.0")]

The issue now is that I have to extract the 1.0.0.0 out. Here's the regular expression that I can come out with:

 var  pattern = "[^\\/]+\\[[a-z]+:\\s" + "AssemblyVersion"+ "(?:Attribute)?\\((.+)\\)\\]" ;
 var theString ="[assembly: AssemblyVersion("1.0.0.0")]";
 var reAssemblyVersion = new RegExp(pattern,"m");
 reAssemblyVersion.exec(theString);
 var theAnswer = RegExp.$1;       // theAnswer is "1.0.0.0", but I want it to be 1.0.0.0

There must be something I did wrong in setting up the pattern variable, but couldn't find out.. any ideas?

+1  A: 

Your RegEx did not eliminate the double qoutes.

Here is the right one:

var  pattern = "[^\\/]+\\[[a-z]+:\\s" + "AssemblyVersion"+ "(?:Attribute)?\\(\\\"(.+)\\\"\\)\\]" ;
//  Here --------------------------------------------------------------------^^^^    ^^^^

Hope it helps

NawaMan
A: 

Why can't you just have something simple as this:

\(\"([0-9.]*)\"\)
DmitryK