I\'m working with RegEx on Javascript and here is where I stuck.
I have a simple string like
Try this regex instead:
<[^>]+>
DEMO:
http://regex101.com/r/kI5cJ7/2
DISCUSSION
Put the html code in a string and apply to this string the regex.
var htmlCode = ...;
htmlCode = htmlCode.replace(/<[^>]+>/g, '');
The original regex take too much characters (*
is a greedy operator).
Check this page about Repetition with Star and Plus, especially the part on "Watch Out for The Greediness!".
Most people new to regular expressions will attempt to use
<.+>
. They will be surprised when they test it on a string likeThis is a first test
. You might expect the regex to matchand when continuing after that match,
.
But it does not. The regex will match
first
. Obviously not what we wanted.