"); string str = "burn"; int x=0; if(reg.IsMatch(str)-6ren">
gpt4 book ai didi

c# - C# 中的正则表达式

转载 作者:太空宇宙 更新时间:2023-11-03 17:59:21 24 4
gpt4 key购买 nike

我想用C#写Regex,我写了下面的代码:

Regex reg = new Regex("n>");
string str = "burn";
int x=0;
if(reg.IsMatch(str))
x++;

但是,x 始终等于零。有谁知道为什么吗?

谢谢,雷切尔

最佳答案

您的意思是通过 > 匹配单词边界,但这些在 .NET 正则表达式中由 \b 表示:

Regex reg = new Regex("n\\b");  // alternatively: Regex(@"n\b");

关于c# - C# 中的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4104458/

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