[英]I want to remove brackets from text before hyphen only in php regular expression
I have this string: 我有这个字符串:
(3330) - PATRIOT SPRAYER (11/08-)
And I want to remove brackets only from 3330
. 我只想从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
和与PHP preg_replace
$line = preg_replace('~^\(([^)]+)\)~', '$1', $line);
How about: 怎么样:
$str = '(3330) - PATRIOT SPRAYER (11/08-)';
$str = preg_replace('/\(([^)]+)\)(\s*-)/', "$1$2", $str);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.