preg_match regular expression to pick text between tag

Asked

Viewed 221 times

1

What would be the expression of the preg_match to get the text "exit" within the following tag?

<a href="/logout" role="menuitem">
                            <i class="icon-key"></i> Sair
                        </a>

  • 2

    Regular expression to treat HTML is not the best solution. What language do you want to do this? PHP? If so, use the class DOMDocument.

  • 1

    As we have no information on where, how or why the OP needs to do this, use the DOMDocument just for that it would be

  • 2

    @Brunoaugusto in this case, you wouldn’t even know it’s an ant, so taking a cannon would be appropriate. I say this because if the HTML varies in any detail, the regular expression is invalidated and the application stops working. And for an HTML to change is very easy...

  • David did not throw any stone at Goliath. The most suitable tool for the task was chosen. For something so simple Simplexml spare

1 answer

1


The expression would look like this:

<a href="\/logout" role="menuitem">[\s]+<i class="icon-key"><\/i> ([a-zA-Z]+)[\s]+<\/a>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.