如何更换所有符号,除了 - [英] How do I replace all the symbols except -

查看:72
本文介绍了如何更换所有符号,除了 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在shell脚本中工作。我想将所有符号替换为下划线,除了短划线( - )。

我尝试了很多方法,但它没有用。



我试图删除破折号,但仍然是相同的。



这是我的代码;







Hi All,

I work in shell script. I want to replace all the symbols into underscore except the dash (-).
I'm trying many ways, but it didn't work.

I'm try to delete the dash but is still the same.

This my code;



$string_with_underscore = preg_replace('#[^A-Za-z0-9.]#i', '_', $string_change);
$string_changed = preg_replace('~([^0-9a-zA-Z])\1+|(?:=[*])+|(?:->)+~', '_',  $string_with_underscore);

推荐答案

string_with_underscore = preg_replace('#[^ A-Za-z0-9。] #i',' _',
string_with_underscore = preg_replace('#[^A-Za-z0-9.]#i', '_',


string_change);
string_change);


string_changed = preg_replace('〜([^ 0-9a-zA-Z])\ + + |(?:= [*])+ |(?: - >)+〜','_',
string_changed = preg_replace('~([^0-9a-zA-Z])\1+|(?:=[*])+|(?:->)+~', '_',


这篇关于如何更换所有符号,除了 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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