要求:去掉小数点前的连续数字和小数点后的连续数字及小数点,例如:
去年5G业务收入为65.44亿元,要使用正则表达式去掉65.44这个数字,但不要去掉
5G前面的5。
最好用C#实现
[0-9]+.[0-9]+
using System.Text.RegularExpressions 声明
Regex.IsMatch(inputerstr, "^([0-9]{1,}[.][0-9]*)$") 获取
用replace 删除
不知道对不对
string result = Regex.Replace("去年5G业务收入为65.44亿元", "[0-9]+.[0-9]+", "");
测试result结果是去年5G业务收入为亿元
sed 's/[0-9]*.[0-9]*//g' result
root@localhost.localdomain:[/home/liu]sed 's/[0-9]*.[0-9]*//g' result
去年5G业务收入为亿元
root@localhost.localdomain:[/home/liu]cat result
去年5G业务收入为65.44亿元
root@localhost.localdomain:[/home/liu]
Regex myRegex=new Regex(@"[1-9]+.[1-9]+");
if(myRegex.IsMatch(textBox1.ToString()))
{
textBox1.Text= myRegex.Replace(textBox1.Text.ToString(), "",1);
}