regex - php preg_match_all href inner texts with upper and lower case sensitivity -


i can count number of matching links preg_match_all() function below, checked if inner text of link equal specified keyword.

// text contains 2 different links, whereby inner  // text of first link capitalized , second link starts small letter.    $string = "<p><a href=\"www.link1.com\" class=\"someclass\" title=\"lorem\">lorem</a> dolor sit amet, consectetur         adipiscing elit. in iaculis, libero aliquam lacinia feugiat, <a href=\"www.link2.com\" class=\"someclass\" title=\"lorem\">lorem</a>         elit congue risus, sed sagittis turpis tortor eget orci. integer lacinia quis nisi ac aliquet. sed et convallis diam.</p>";   // count al matches upper , lowercase sensitivity preg_match_all('/<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>lorem<\/a>/siu', $string, $match);  

now question how can make regex it's works matches capital letter.

please use approach instead, e.g. xpath:

$xml = simplexml_load_string($string); $links= $xml->xpath("//a"); foreach ($links $link)     echo $link["href"]; 

see a demo on ideone.com. solution regex be:

~(?i)href=('|")(?<link>[^'"]+)\1(?i-)~ # case-insensitive # href= literally # single/double quote , capture in group 1 # match not singel or double quote 1 or more times # match first captured group again # , turn case sensitivity on again 

a demo can found on regex101.com, better use first approach.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -