gpt4 book ai didi

c# - 如何为 "123456#"编写正则表达式以打印 123456?

转载 作者:行者123 更新时间:2023-11-30 19:18:16 25 4
gpt4 key购买 nike

您好,我需要一个正则表达式来用 ""(emptyString) 替换 # 或 * 我已经尝试使用 /[\\*\\#]/g 但似乎没有用。

http://ideone.com/MtjsX5

在此需要您的帮助。

我实际上使用的是如下所示的 Grxml 语法

SWI_meaning          = DIGITS.SWI_literal.replace( /[ ]+/g, '' );
SWI_meaning = SWI_meaning.replace( /[\*\#]/g, '' );

谢谢

最佳答案

除了正则表达式,您还可以使用 char.IsDigit 仅从字符串中过滤掉数字。尝试以下操作。

string str = "123456#";
string newString = string.Join("",
str.Select(r=> char.IsDigit(r) ? r.ToString():""));

编辑:礼貌@L.B

string newString = String.Join("",str.Where(char.IsDigit));

关于c# - 如何为 "123456#"编写正则表达式以打印 123456?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13450620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com