Regex: Finding The Correct Occurrence Order Of Some Given Special Characters In A String
I want a regular expression that would be able to find the correct occurrence order of * | . | # | 'any HTML element type' like 'p' or 'div' LIKE var regex = //Some regular expr
Solution 1:
You might be better off matching #
and .
along with their respective values and filtering the results afterwards:
var regex = /\*|([#.]\w+)|(\w+)/g
matches = pattern_1.match(regex).map(function(x) { return x.match(/^[#.]/) ? x.charAt(0) : x })
or remove the id/class names first, and then match:
matches = pattern_1.replace(/([#.])\w+/g, "$1").match(/[.#*]|\w+/g)
Post a Comment for "Regex: Finding The Correct Occurrence Order Of Some Given Special Characters In A String"