使用正则表达式获取标签中的第一个单词 [英] Getting the First Word in a Tag With Regex
本文介绍了使用正则表达式获取标签中的第一个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个正则表达式来获取 < 中的第一个单词... >
标签.我已经有了一个可以获取标签中所有单词的方法.我正在使用它:
I'm trying to make a regex to get the first word in a < ... >
tag. I already have one to get all the words in a tag. I'm using this for it:
/<(.*?)>/
我的问题是,我可以使用正则表达式获取标签中的第一个单词吗?
My question is, can I get the first word in a tag using a regex?
推荐答案
这是一个可行的解决方案:/<([^>\s]+)[^>]*>/
Here's a working solution: /<([^>\s]+)[^>]*>/
这篇关于使用正则表达式获取标签中的第一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文