【问题标题】:How to avoid matching numeric string that has # at the beginning? [duplicate]如何避免匹配以#开头的数字字符串? [复制]
【发布时间】:2019-01-28 06:30:10
【问题描述】:

我正在使用下面的正则表达式来匹配包含小数、引号 (") 内的负数的数字。 我应该进行哪些更改以使其与“#1200”不匹配?

\"(-?\d*.?\d+)\"

"1200"     ---> matches as expected
"1200.67"  ---> matches as expected
"-1200"    ---> matches as expected
"-1200.67" ---> matches as expected
"#1200"    ---> I'm not expecting this to match. As you can see It has # at the beginning.

【问题讨论】:

  • 你需要转义.

标签: c# .net regex regex-negation


【解决方案1】:

我相信这是您正则表达式中的.。你没有逃脱它,所以它被解释为“匹配任何字符”。如果你像这样逃避它应该可以工作:

\"(-?\d*\.?\d+)\"

【讨论】:

  • 谢谢!它有效。
猜你喜欢
  • 2020-08-30
  • 2014-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-09
  • 2020-01-04
  • 2017-08-20
  • 1970-01-01
相关资源
最近更新 更多