查找完整的标签
编写一个正则表达式来查找标签<style...>。它应该匹配完整的标签:它可能没有属性<style>,或者有几个属性<style type="..." id="...">。
…但正则表达式不应该匹配<styler>!
例如
let regexp = /your regexp/g;
alert( '<style> <styler> <style test="...">'.match(regexp) ); // <style>, <style test="...">
模式的开头很明显:<style。
…但我们不能简单地写<style.*?>,因为<styler>会匹配它。
我们需要在<style之后有一个空格,然后是可选的其他内容,或者结束符>。
在正则表达式语言中:<style(>|\s.*?>)。
在行动中
let regexp = /<style(>|\s.*?>)/g;
alert( '<style> <styler> <style test="...">'.match(regexp) ); // <style>, <style test="...">