如何从字符串中获取AZ和0-9?
如何从“Lörum ipsäm 1!”中获取“Lrumipsm1”?
所以我需要的是使用 php 仅从字符串中获取 az 和 0-9。
How do I get "Lrumipsm1" from "Lörum ipsäm 1!"?
So what I need is to only get a-z and 0-9 from a string, using php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如,通过使用正则表达式(pcre)并替换不属于“可接受的”类的所有字符" 字符由 '' 组成。
另请参阅:http://docs.php.net/preg_replace
编辑:
[a-z0-9]
是所有字符 a....z 和 0...9 的类[^...]
否定一个类,即[^a-z0-9]
包含 .. 中不的所有字符。 .z0...9+ 是量词,含义为“1 次或多次”,
[^a-z0-9]+
匹配不在 a...z0..9 范围内的一个或多个(连续)字符.选项
i
使模式不区分大小写,即 [az] 也匹配 A...ZE.g. by using a regular expression (pcre) and replacing all characters that are not within the class of "acceptable" characters by ''.
see also: http://docs.php.net/preg_replace
edit:
[a-z0-9]
is the class of all characters a....z and 0...9[^...]
negates a class, i.e.[^a-z0-9]
contains all characters that are not within a...z0...9+ is a quantifier with the meaning "1 or more times",
[^a-z0-9]+
matches one or more (consecutive) characters that are not within a...z0..9.The option
i
makes the pattern case-insensitive, i.e. [a-z] also matches A...Z你也可以这样做
you can do this also