Need regular expression grouping

I want to get a regex for the following construct, where it should look like:

Actions and Sci-Fi

<a href="/?genre=Action">Actions</a> <a href="/?genre=Sci-Fi">Sci-Fi</a>
+4
source share
1 answer

Do not parse html files with regular expression. If you insist, you can use the following regular expression and get the text inside the anchor tags from group 1 index.

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

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>'
+4
source

All Articles