简体   繁体   English

PHP字符串替换修饰符

[英]PHP string replace modifiers

I am trying to write some string replace functions, and rather than ask how to do a specific replace, I want to know more about modifiers so I can do it myself 我正在尝试编写一些字符串替换函数,而不是问如何进行特定的替换,我想更多地了解修饰符,以便自己完成

Take this for example: 以这个为例:

preg_replace('~[\W\s]~', ' ', $input);

or 要么

strlen(preg_replace('![^A-Z]+!', '', $s));

What are those called? 这些叫什么? (~[\\W\\s]~) (![^AZ]+!) They make very little sense to read or make up a new one. (〜[\\ W \\ s]〜)(![^ AZ] +!)阅读或组成新书几乎没有意义。 Where can I find all of them? 在哪里可以找到所有这些? Or learn how to write them? 还是学习如何写它们?

They are called Regular Expressions. 它们称为正则表达式。 From http://www.regular-expressions.info , 'A regular expression (regex or regexp for short) is a special text string for describing a search pattern. http://www.regular-expressions.info中 ,“正则表达式(简称regex或regexp)是用于描述搜索模式的特殊文本字符串。 You can think of regular expressions as wildcards on steroids.' 您可以将正则表达式视为类固醇的通配符。

Here is a site with references and a playground to test working with them. 这是一个有参考资料的站点和一个测试与之合作的操场。

http://regexr.com http://regexr.com

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

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