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
How about the simpler
str.match(/[^%]*/i)[0]
Which means, match zero-or-more character, which is not a %
.
Edit: If need to parse until , then you could parse a sequence pf characters, followed by
, then then discard the
, which means you should use positive look-ahead instead of negative.
str.match(/.*?(?=<\/a>|$)/i)[0]
This means: match zero-or-more character lazily, until reaching a or end of string.
Note that *?
is a single operator, (.*)?
is not the same as .*?
.
(And don't parse HTML with a single regex, as usual.)