JavaScript Regex pull out only a number in an element

How would one go about pulling out just a number in the text of an element? I want to set this as a variable.

ie. If I wanted to have a variable made from option val 171 of the number 12 so I can do calculations with it (I just want to be left with the number 12):

<select id="coloroption">
 <option value="172">Granite Gray</option>
 <option value="174">Hot Red</option>
 <option value="173">Navy</option>
 <option value="171">Kentucky Green (min. 12)</option>
</select>

Answers


var number = $('#coloroption option[value="171"]').text().match(/\d+/);

Live demo. Depending on the possible values of this option and what you need to extract from it, the regex might need tweaking.


Need Your Help

IntelliJ not using external Jar's if not added via Maven when running JSF application?

java maven tomcat intellij-idea dependencies

I have a very simple line of code that is called from an .xhtml file ( in a JSF 2.0 project ) which looks like:

CSS Fix container and overflow elements

css overflow containers fixed

Iam wondering if it is a way to force overflow elements of an fixed container to be on the same line instead of going on a new line.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.