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.
also, if want prevent other characters before or after matched string, may need add start (^
) , end ($
) anchor:
/^(\d+(?:\.\d+)?).+?(\d+(?:\.\d+)?)$/
Comments
Post a Comment