本文介紹了一系列 unicode 點 PHP 的正則表達式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我試圖從字符串中去除所有字符,除了:
I'm trying to strip all characters from a string except:
- 字母數字字符
- 美元符號 (
$
) - 下劃線 (
_
) - 代碼點
U+0080
和U+FFFF
之間的Unicode字符
- Alphanumeric characters
- Dollar sign (
$
) - Underscore (
_
) - Unicode characters between code points
U+0080
andU+FFFF
我通過這樣做獲得了前三個條件:
I've got the first three conditions by doing this:
preg_replace('/[^a-zA-Zd$_]+/', '', $foo);
如何匹配第四個條件?我查看了使用 X
但有必須比列出 65000 多個字符更好.
How do I go about matching the fourth condition? I looked at using X
but there has to be a better way than listing out 65000+ characters.
推薦答案
您可以使用:
$foo = preg_replace('/[^w$x{0080}-x{FFFF}]+/u', '', $foo);
w
- 相當于[a-zA-Z0-9_]
x{0080}-x{FFFF}
匹配代碼點U
+0080和
U+FFFF`<之間的字符/li>/u
用于正則表達式中的 unicode 支持w
- is equivalent of[a-zA-Z0-9_]
x{0080}-x{FFFF}
to match characters between code pointsU
+0080and
U+FFFF`/u
for unicode support in regex
這篇關于一系列 unicode 點 PHP 的正則表達式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!