Reputation:
I have a dynamic string with English and Icelandic characters:
$string = "The Post (Post Title In Icelandic Characters) appeared first on (Website Name)";
The title could contain any special characters like (- _ , . & ..Etc Etc).
The website name sometimes contain Icelandic characters and special characters like (. -).
Both title and website name should be case insensitive, As some words contain capital letters.
I tried:
$appeared= ['~The post [^\p{Xwd}. -] appeared first on [^"]*~u'];
preg_replace($appeared, '', $string)
But it didn't work.
An example:
$string = "The post Gufuá í Borgafirði – flott veiði í dag, 26. júní appeared first on a.is.";
Please note that the title contains special characters, It could contain any special character, Also the dot at the end of the string may exist or not.
I want to replace that full string with empty string ''.
Upvotes: 0
Views: 238
Reputation: 626825
It appears you need
preg_replace('~The post .*? appeared first on .*~', '', $string)
The first .*?
matches any 0+ chars other than line break chars, as few as possible (lazy), and then the last .*
matches 0+ chars other than line break chars, as many as possible (greedy).
See the PHP demo.
Note you do not really need to worry about Icelandic chars here since you only want to match any characters.
Upvotes: 1