regex - Javascript regexp expression that matches two digits in a string with optional decimal places -


how modify following javascript regexp matches of proceeding patterns?

/(\d\d).+?(\d\d)/  2 of 5 2.5 of 5.6 2.3 of 10 100.4 of 1000 1000.4 of 10000.3 

try this:

/(\d+(?:\.\d+)?).+?(\d+(?:\.\d+)?)/ 

this match 1 or more decimals followed optional decimal point , 1 or more decimals, captured in group 1, followed 1 or more of character, non-greedily, followed 1 or more decimals followed optional decimal point , 1 or more decimals, captured in group 2.

demonstration

also, if want prevent other characters before or after matched string, may need add start (^) , end ($) anchor:

/^(\d+(?:\.\d+)?).+?(\d+(?:\.\d+)?)$/ 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -