My text:
var str = 'Cost USD 400.00';
How to use jquery to search for a number on this line only?
You should probably not use jQuery; You should use the built-in Javascript regex support. In this case, your regular expression might look like this:
var result = /\d+(?:\.\d+)?/.exec(mystring);
The official link to this is: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/RegExp .
What gillyb said, but I would add:
var str=new RegExp("\\d+\.?\d+?");
To get anything after the decimal point.
The above RegEx must comply
400
400.01
400,0
400,001
http://xenon.stanford.edu/~xusch/regexp/analyzer.html ... http://www.regular-expressions.info/javascriptexample.html
1, , , 2, , SHOW MATCH.
, .
Just find the number using a simple RegEx object in javascript. There is no need for jQuery.
eg:
var str = new RegExp("\\d+(?:\\.\\d+)"); var num = str.exec("Cost USD 400.00");
Source: https://habr.com/ru/post/1756029/More articles:JQuery image in div, makes code weird - jqueryEvent Triggering Event - c #svcutil.exe - Ошибка: не удалось импортировать wsdl: portType - c#Reading in Intel Hex file to sort C ++ - c ++LINQ To SQL - получать последние записи, соответствующие условиям where - linq-to-sqlMVVM Light - WP7 Page / Applications - windows-phone-7Can you use ConcurrentDictionary to match one to many? - c #C Handles - How to work with them? - cHow to implement a custom delimited container in Flex 4? - flex4Globe with rpm python module? - pythonAll Articles