I have this string:
(3330) - PATRIOT SPRAYER (11/08-)
And I want to remove brackets only from 3330
. Expected output:
3330 - PATRIOT SPRAYER (11/08-)
I have tried to use:
$pattern = ('/[[(.)]]/')
But I don't get my expected result. Where did I go wrong?
You could use ^
to mark the start of the line. This would give you an regex like the following:
^\(([^)]+)\)
and the with php preg_replace
$line = preg_replace('~^\(([^)]+)\)~', '$1', $line);
How about:
$str = '(3330) - PATRIOT SPRAYER (11/08-)';
$str = preg_replace('/\(([^)]+)\)(\s*-)/', "$1$2", $str);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.