I'm trying to see the existence of /target- in a string of /dir1/dir2/dir3/dir4/../dir7/dir8/dir9/target-.a-word1-word2-alphanumberic1-alphanumberic2.md).
$re = '/^(.*?)(\/target-)(.*?)(\.md)$/i';
$str = '/dir1/dir2/dir3/dir4/../dir7/dir8/dir9/target-.a-word1-word2-alphanumberic1-alphanumberic2.md';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
// Print the entire match result
var_dump($matches);
Demo: https://regex101.com/r/Saxk8x/1
Do I use preg_match or preg_match_all or are there faster or easier ways to do so?
Both preg_match or preg_match_all return null, even though Demo functions properly.