如何使用Windows Batch脚本中的REGEX从字符串中删除字母和特殊字符? [英] How to remove alphabets and special characters from a string using REGEX in Windows Batch Script?

查看:110
本文介绍了如何使用Windows Batch脚本中的REGEX从字符串中删除字母和特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除字母a到z,A到Z和特殊字符.我只需要数字和小数点.我发现了很多使用字符串操作的示例,但我认为使用正则表达式会更好.

I need to remove letters a to z , A to Z and special characters. I only need digits and decimal point. I found a lot of examples using string manipulations but I think it is better to use regular expressions.

例如,

数字= 10.20af24

数字必须等于10.20,而不是10.20af24.

numbers must be equal to 10.20 and not 10.20af24.

谢谢.

推荐答案

一个

@echo off

    setlocal enableextensions enabledelayedexpansion
    set "string=10.20af24"
    set "num="
    for /f %%a in ('cmd /q /u /c "echo(%string%"^|more^|findstr /r /c:"[0-9.]"') do set "num=!num!%%a"

    echo %num%

这篇关于如何使用Windows Batch脚本中的REGEX从字符串中删除字母和特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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