简体   繁体   中英

Regular Expression that matchis something or nothing

I am trying to find a value between two HTML tags ie: <td></td>

There can either be a word character \\w or nothing (not even a space between the >< closing an opening bracket.

So I am trying this /<td>[\\w{1,}|]<\\/td>/ but it is not working.

This is for php, and yes, I am well aware of some people warning against parsing HTML with regular expressions ;) ...

Any help would be appreciated.

Thank you

/<td>\w*<\/td>/

If you are trying to have matching groups, you need parentheses not brackets:

/<td>(\w*)<\/td>/

To match "nothing", just make the term optional with an *

If you need to find a value between two html tags. Please use bellow regex

(?<td>)(\w*)(?=<\/td>)

It just match only the word or nothing in between <td></td>

https://regex101.com/r/4Cy2xZ/1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM