gpt4 book ai didi

c# - 字符串格式或REGEX

转载 作者:太空宇宙 更新时间:2023-11-03 18:18:25 25 4
gpt4 key购买 nike

我需要一种简单的方法来检查发送到我的函数的字符串是否具有以下格式:

(x + n)(x + m) 
//the +'s can be minus'
//n and m represent a double
//x represents the char 'x'


是否可以使用一种简单的字符串格式来检查这是表格。与单个检查每个字符相反。

空格将被删除,以免造成任何混乱。

问候

劳埃德

最佳答案

这是RegEx示例的一个刺...

var pattern = @"^(\(x[+-]\d+(\.\d+)?\)){2}$";
var input = "(x-0.123)(x+5)";
var result = System.Text.RegularExpressions.Regex.IsMatch(input, pattern);

if (result) {
Console.Write("YAY IT MATCHES");
}

关于c# - 字符串格式或REGEX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2457063/

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