星号-使用正则表达式在字符串中查找字符* [英] Star - look for the character * in a string using regex

查看:79
本文介绍了星号-使用正则表达式在字符串中查找字符*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在字符串中找到以下文本:'***'事实是C#Regex机制不允许我执行以下操作:

I am trying to find the following text in my string : '***' the thing is that the C# Regex mechanism doesnt allow me to do the following:

new Regex("***", RegexOptions.CultureInvariant | RegexOptions.Compiled);

由于

ArgumentException:正在解析" * -量词{x,y}不跟随任何内容."

ArgumentException: "parsing "*" - Quantifier {x,y} following nothing."

很明显,它认为我的星星代表正则表达式,有没有办法告诉正则表达式机制将恒星视为恒星而不是其他东西?

obviously it thinks that my stars represents regular expressions, is there a way to tell the Regex mechanism to treat stars as just stars and nothing else?

推荐答案

您需要用反斜杠转义: @"\ *"

这篇关于星号-使用正则表达式在字符串中查找字符*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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