简体   繁体   English

需要正则表达式的分组

[英]Need Grouping of Regular Expression

I want to get regex for the following construct where it should result as: 我想得到以下构造的正则表达式,它应该导致:

Actions and Sci-Fi 行动和科幻

<a href="/?genre=Action">Actions</a> <a href="/?genre=Sci-Fi">Sci-Fi</a>

Don't parse html files with regex. 不要使用正则表达式解析html文件。 If you insist then you could use the below regex and get the text inside anchor tags from group index 1. 如果您坚持,那么您可以使用以下正则表达式并从组索引1中获取锚标记内的文本。

<a\s[^<>]*>([^<>]*)<\/a>

DEMO DEMO

Explanation: 说明:

<a                       '<a'
\s                       whitespace (\n, \r, \t, \f, and " ")
[^<>]*                   any character except: '<', '>' (0 or more
                         times)
>                        '>'
(                        group and capture to \1:
  [^<>]*                   any character except: '<', '>' (0 or
                           more times)
)                        end of \1
<                        '<'
\/                       '/'
a>                       'a>'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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