I have a regEx for checking a number is less than 15 significant figures, Borrowed from this SO answer
/^-?(?=\d{1,15}(?:[.,]0+)?0*$|(?:(?=.{1,16}0*$)(?:\d+[.,]\d+))).+$/
The the other is used to check that same number is upto 2 decimal places(truncate)
/^-?(\d*\.?\d{0,2}).*/
I have almost 0 regex skill.
Question: How do I combine the 2 regexes to do the work of both, AND not just either OR( accomplished by | character - i am not sure if it achieves same function as combining both)
something like:
/^-?(?=\d{1,15}(?:[.,]0+)?0*$|(?:(?=.{1,16}0*$)(?:\d+[.,]\d+))).+$ <AND&&NOTOR>(\d*\.?\d{0,2}).*/
Thanks in advance
EDIT: edit moved to a seperate SO question
If you add only one condition of maximum 2 decimal places to first regex, try this..
Demo,,, in which I only changed original
\d+
tod{1,2}$
Edited for the reguest to extract
15 significant figures
and capturegroup 1
($1
). Try this which is wrapped to capturegroup 1
($1
) and limited15 significant figures
to be extracted easily.Demo,,, in which changed to
.{1,16}
from.+$
. If the number matches, then able to be replaced$1
, but if not so, replaced nothing, thus remains original unmatched number.Therefore, if you want to extract
15 significant figures
by replacing with$1
only when your condition is satisfied, try this regex to your function.Demo,,, in which all numbers are matched, but only
the numbers satisfying your condition
are captured to$1
in format of15 significant figures
.