I have a string like
5|10|20|200|300
and i want to get the First Digit Before |
and last digit after |
that is 5 and 300.
How would I use regex in javascript to return that numbers??
This simplest regex will return the two matches 5
and 300
:
^\d+|\d+$
See the matches in the demo.
In JS:
result = yourString.match(/^\d+|\d+$/g);
Explanation
^\d+
matches the beginning of the string and some digits (the 5
)|
\d+$
matches some digits and the end of the stringIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With