简体   繁体   English

Preg匹配所有字符

[英]Preg match all characters

how to preg match all characters letters, numbers, special characters fe: ²,▲,ƒ ² ‰ © £ ± ß ° 1/2 ¿ « » ™...etc...??? 如何preg匹配所有字符字母,数字,特殊字符fe:²,▲,ƒ²‰²°²°1/2¿«»™......等等......

and others special characters??? 和其他特殊字符???

The regex syntax for any character except line breaks (\\r or \\n) is . 除换行符(\\ r或\\ n)之外的任何字符的正则表达式语法是. , thus if you wanted to match one or more of any character, your regex would simply be .+ reference . 因此,如果你想匹配任何一个或多个角色,那么你的正则表达式就是.+ reference However, some regex flavours do permit you to specify a flag which will allow the . 但是,一些正则表达式允许你指定一个允许的标志. to include line break characters. 包括换行符。

As noted by Damien, what is the point of using preg_match? 正如Damien所说,使用preg_match有什么意义?

In RegEx, the dot sign (.) will match any character, so 在RegEx中,点号(。)将匹配任何字符,所以

preg_match('/hel.o/', $str);

Will match hello , helpo , hel o , hel%o etc. 将匹配hellohelpohel ohel%o等。

[\\w\\W] or [\\s\\S] matches all characters, including line breaks. [\\w\\W][\\s\\S]匹配所有字符,包括换行符。

But these expressions are much slower then . 但是这些表达式要慢得多. , so be careful when working with big strings. ,使用大字符串时要小心。

点( . )代表任何字符。

you may need to append /u in the pattern to tell preg_match to use utf8 strings, check manual for /u option and just paste the simple in the php code. 您可能需要在模式中追加/ u以告诉preg_match使用utf8字符串,检查/ u选项的手册并将简单粘贴到php代码中。

just remember to save the .php in utf8 mode or do some decodes manually. 只记得在utf8模式下保存.php或手动执行一些解码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM