2

我有一个字符串,其中包含英语和非英语字符,并且它们都包含它们underscore symbol _之间的字符。

我只想从非英语字符串中删除下划线,只留下英文字符之间的下划线。

示例:Hello_this is me , مرحبا_اناهنا

谢谢!

4

3 回答 3

0

这个 preg_replace 可能有效:

preg_replace('/(?<=[^\x00-\x80])_(?=[^\x00-\x80])/', '', $str);
于 2013-06-26T22:03:18.957 回答
0

这应该做你想要的:

preg_replace('/(?<=\p{Arabic})_(?=\p{Arabic})/', '', $s)

查看http://www.php.net/manual/en/regexp.reference.unicode.php

于 2013-06-26T22:12:15.777 回答
0

你可以试试这个:

<meta charset="UTF-8"/>
<pre><?php

$subject = "Hello_this is me , مرحبا_اناهنا";

$pattern = '~\p{Arabic}\K_(?=\p{Arabic})~u';

echo $subject . '<br/>' . preg_replace($pattern, ' ', $subject);

请注意,我使用 u 修饰符来处理 unicode 字符串。

重置它之前的\K匹配,但您可以通过后视替换这个技巧作为 anubhava 和 ctn 建议它。

于 2013-06-26T22:19:56.327 回答