Skip to main content
 首页 » 编程设计

c#之C# 中的正则表达式查找类似 "x-[some_string]"的匹配项

2024年05月06日35lexus

C# 中用于在文本中查找匹配项的正则表达式是什么 以“x-[”开头并以“]”结尾?

我试过这样的:

Regex urlRx = new Regex(@"^x-[.*]$", RegexOptions.IgnoreCase); 

请您参考如下方法:

简单:

x-\[([^]]+)\] 
# that is: look for x-[ literally 
# capture and save anything that is not a ] 
# followed by ] 

参见 a demo on regex101.com .