I've PHP String of around 4000 chars; if anywhere in this PHP string $input1, $input2 or $input3 is identified, I want to replace same with $output string. In Summary I want to remove " ewline" after "\end{Figure}"
$input1 = "\end{Figure}
ewline";
$input2 = "\end{Figure}
ewline";
$input3 = "\end{Figure}
ewline "
Required output:
$output = "\end{Figure}";
Can you please suggest how to achieve required output?
Your question is not very clear, but perhaps this is what you are looking for:
$result = preg_replace('~\\\end\{Figure}\K( )?\\
ewline(?(1)| )~', '', $text);
pattern details:
~ # pattern delimiter
\\\ # backslash (must be double escaped inside quotes)
end\{Figure}
\K # reset the begining of the match
( )? # optional capturing group n°1
\\
ewline
(?(1)| ) # if capturing group n°1 exists there is nothing else a space
~