Guys how to write a regex that delete everything after faqs?
$str1 = "/faqs/broker-type"; $str2 = "aaa <a href='/faqs/broker-type'>text</a>"; $str3 = 'aaa <a href="/faqs/broker-type">text</a>'; $patterns = [ '/faqs/' ]; $replacements = array(); echo preg_replace($patterns, $replacements, $str1); The result I want to get the following: That is, to delete everything after / faqs before single, double quotes and spaces.
$str1 = "/faqs"; $str2 = "aaa <a href='/faqs'>text</a>"; $str3 = 'aaa <a href="/faqs">text</a>'; help me please
<a href='..or there may be variants like<a target='_blank' href='...'>well, and double quotes instead of single quotes are found. This is all very complicated expression. If the links were the same, it would be possible to change something like/<a href='/faqs/\K.*?'/change by one quote ... - Mike/faqs/this is not found in the text/faqs/That is, if there is/faqs/then this is the line I need - user216109<ayou are changing the same. on the one hand it is easier, on the other - it is necessary to understand where it will stop. you can cut after, for example, all non-whitespace characters to the next space or quotes/\/faqs\/\K.*?([\s'"]+)/change to$1that is, these are the quotes or whatever after the link - Mike/faqs/in $ str2, and a double quote in $ str3? - Visman