开发者

how to express this in regex

开发者 https://www.devze.com 2023-04-10 19:21 出处:网络
I have this : <title>Title</title> All I want to do is express this in regex. I have: /<[A-Za-z]>\\w<\\/[开发者_开发知识库A-Za-z]>

I have this :

<title>Title</title>

All I want to do is express this in regex. I have:

/<[A-Za-z]>\w<\/[开发者_开发知识库A-Za-z]>

Can anyone help


You need a + after each of the [] and after the \w to represent "one or more".

/<[A-Za-z]+>\w+<\/[A-Za-z]+>/

But it looks like you're trying to parse HTML with regex. You might want to consider not doing that.


You should use a backreference. If you don't then you will match:

<title>blabla</otherTag>

Try this:

/<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>(.*?)</\1>/
0

精彩评论

暂无评论...
验证码 换一张
取 消