Skip to content

Instantly share code, notes, and snippets.

@Lenny4
Created September 26, 2023 17:57
Show Gist options
  • Save Lenny4/0bf3370ffba7b833ff76fe4017fa0a48 to your computer and use it in GitHub Desktop.
Save Lenny4/0bf3370ffba7b833ff76fe4017fa0a48 to your computer and use it in GitHub Desktop.
Match all html tag except `<s></s>` and `<strong></strong>`
### Match all html tag except `<s></s>` and `<strong></strong>` :
- `<(?!\/?(s|strong)(?=>|\s.*>|\/>))\/?.*?>`
- source : https://stackoverflow.com/questions/29869/regex-to-match-all-html-tags-except-p-and-p#answer-2928149
- php
```
<?php
function regexHtmlTags($string)
{
$arrayTags = ["s", "strong", "em", "p"];
$pattern = "/<(?!\/?(" . implode($arrayTags, '|') . ")(?=>|\s.*>))\/?.*?>/";
return preg_replace_callback($pattern, function ($matches) {
return htmlspecialchars($matches[0]);
}, $string);
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment