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
I just wrote it exactly how you said it:
str.match(/(^[^%]*$)|^([^%]*)%.*/i)
This will match any string without a '%' or the first part of a string that contains a %. You have to get the result from the 1st or 2nd group.
EDIT: This is exactly what you want below
str.match(/(?:^[^%]*$)|^(?:[^%]*)(?=%)/)
so the regex reads match any string that doesnt contain %, OR (otherwise match) all of the characters before the first %