Currently I have
Input: e.g., '123456789'.'+'.'987654321'
Desired Pattern:
Output: e.g., '123456789987654321'
How can I achieve this using in php ? I am not through on regex and so what regex would go in preg_replace for this ?
Currently I have
Input: e.g., '123456789'.'+'.'987654321'
Desired Pattern:
Output: e.g., '123456789987654321'
How can I achieve this using in php ? I am not through on regex and so what regex would go in preg_replace for this ?
I am not sure if I get your question, but if you're asking how to get rid of the plus symbol:
$input = '123456789+987654321';
$output = preg_replace('/([^+]+)\+([^+]+)/', '$1$2', $input);
echo $output, PHP_EOL;
Try this one.
$input = "'123456789'.'+'.'987654321'";
$output = trim("'", preg_replace("/([^+]+)'\.'\+'\.'([^+]+)/", "$1$2", $input));
// Without RegEx
$output = trim("'", str_replace("'.'+'.'", "", $input));
echo $output;
If you only have "123456789+987654321"
as the input and want "123456789987654321"
as the output, you'd just have to remove the "+"
No need for regex:
$output = str_replace("+", "", $input);
If you want to replace this pattern in a bigger string, you can use this regex:
$output = preg_replace("/(\\d+)\\+(\\d+)/", "$1$2", $input);
Note that the "+" has a special meaning in regex and needs to be escaped by a backslash. Additionally, the backslash has a special meaning in PHP strings and needs to be escaped by a backslash itself.
So the above turns into the in-memory string /(\d+)\+(\d+)/
, and the regex engine can understand that you mean multiple digits (\d+
) and a literal plus (\+
).
I think he's actually trying to concatenate
$customer_id = 123456789;
$operator_domain = 987654321;
$Output = $customer_id.$operator_domain;