parsing “*” - Quantifier {x,y} following nothing

前端 未结 3 2040
[愿得一人]
[愿得一人] 2020-12-06 09:36

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

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

I tr

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 09:56

    You appear to have a lone "*" in your regex. That is not correct. A "*" does not mean "anything" (like in a file spec), but "the previous can be repeated 0 or more times".

    If you want "anything" you have to write ".*". The "." means "any single character", which will then be repeated.

    Edit: The same would happen if you use other quantifiers by their own: "+", "?" or "{n,m}" (where n and m are numbers that specify lower and upper limit).

    • "*" is identical to "{0,}",
    • "+" is identical to "{1,}",
    • "?" is identical to "{0,1}"

    which might explain the text or the error message you get.

提交回复
热议问题