Hi I am new to regular expression and this may be a very easy question (hopefully).
I am trying to use one solution for 3 kind of string
to match 45, 45%, and any number of any length use this (182%, 18242, etc)
str.match(/([0-9]+)([%]?)/)[1];
if you need to match the empty string also include it as ^$, note match("...")[1] will be undefined for the empty string, so you will need to test for match and then check [0] or see if [1] is undefined.
str.match(/([0-9]+)([%]?)|^$/)
if you need to match exactly two digits use {2,2} anchor the expression between begin and end line characters: "^(exp)$"
str.match(/^([0-9]{2,2})([%]?)$/)[1];