解析“ *” -量词{x,y}不跟随 [英] parsing "*" - Quantifier {x,y} following nothing

查看:149
本文介绍了解析“ *” -量词{x,y}不跟随的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

失败。
我该如何解决?

fails when I try Regex.Replace() method. how can i fix it?

Replace.Method (String, String, MatchEvaluator, RegexOptions)

我尝试输入代码

<%# Regex.Replace( (Model.Text ?? "").ToString(), patternText, "<b>" + patternText + "</b>", RegexOptions.IgnoreCase | RegexOptions.Multiline)%>


推荐答案

您是否尝试仅使用字符串 * 作为正则表达式?至少这就是导致您在此处出现错误的原因:

Did you try using only the string "*" as a regular expression? At least that's what causes your error here:

PS Home:\> "a" -match "*"
The '-match' operator failed: parsing "*" - Quantifier {x,y} following nothing..
At line:1 char:11
+ "a" -match  <<<< "*"

字符 * 是特殊字符在正则表达式中,因为它允许前置标记出现零次或多次。

The character * is special in regular expressions as it allows the preceding token to appear zero or more times. But there actually has to be something preceding it.

如果要匹配文字星号,请使用 \ * 作为正则表达式。否则,您需要指定可能重复的内容。例如,正则表达式 a * 不匹配任何内容,或者匹配任意多个 a s。

If you want to match a literal asterisk, then use \* as regular expression. Otherwise you need to specify what may get repeated. For example the regex a* matches either nothing or arbitrary many as in a row.

这篇关于解析“ *” -量词{x,y}不跟随的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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