正则表达式匹配除字母和数字以外的所有字符 [英] Regex to match all characters except letters and numbers

查看:85
本文介绍了正则表达式匹配除字母和数字以外的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想清除所有上传文件的文件名.我想删除除句点、字母和数字之外的所有字符.我不擅长正则表达式,所以我想我会在这里问.有人可以将我指向一个有用的站点或告诉我如何将它们组合在一起吗?我正在使用 PHP.

I want to clean the filenames of all uploaded files. I want to remove all characters except periods, letters and numbers. I'm not good with regex so I thought I would ask here. Can someone point me to a helpful site or show me how to put this together? I'm using PHP.

推荐答案

$newfilename=preg_replace('/[^a-zA-Z0-9.]/','',$filename);

这篇关于正则表达式匹配除字母和数字以外的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆