With PHP preg_replace and regex
$string_1 = "leave sb. alone";
$string_2 = "pick one way forward";
$string_2 = "suffer from sth.";
I need to mask each line with the specified character, but leave the spaces, apostrophe and some line untouched, for example:
$mask_1 = "XXXXX sb. XXXXX";
$mask_2 = "XXXX XXX'X XXX XXXXXXX";
$mask_2 = "XXXXXX XXXX sth.";
In this case, I want to save: sb. STG. spaces and apostrophe. Any help would be greatly appreciated.
with $mask_1 = preg_replace('/(sb.\K)?./s', 'X', $string_1);i leave only 'sb.' but the gaps are still changing.
PS: Both @Casimir et Hippolyte and @Wiktor Stribiżew answers are great solutions, but I took Wiktor to implement and explain SKIP-FAIL. Thank you very much!
Karls source
share