相关疑难解决方法(0)

如何将整个字符串与正则表达式匹配?

我需要一个只能找到整个字符串与我的查询匹配的匹配的正则表达式.

例如,如果我搜索名为"Red October"的电影,我只想匹配那个确切的标题(不区分大小写),但不匹配"The Hunt For Red October"等标题.不太确定我知道怎么做.谁知道?

谢谢!

.net c# regex

69
推荐指数
5
解决办法
6万
查看次数

正则表达式加上和星之间的区别

我尝试从字符串中提取错误号,如"Wrong parameters - Error 1356":

 Pattern p = Pattern.compile("(\\d*)");
 Matcher m = p.matcher(myString);
 m.find();
 System.out.println(m.group(1));
Run Code Online (Sandbox Code Playgroud)

这不会打印任何东西,这对我来说就像来自Wiki*手段一样奇怪* - Matches the preceding element zero or more times

我也去了www.regexr.comregex101.com测试它,结果是一样的,这个表达没什么\d*

然后我开始测试一些不同的东西(在我提到的网站上进行的所有测试):

  • (\d)* 不起作用
  • \d{0,} 不起作用
  • [\d]* 不起作用
  • [0-9]* 不起作用
  • \d{4} 作品
  • \d+ 作品
  • (\d+) 作品
  • [0-9]+ 作品

所以,如果我能找到解释,我开始在网上搜索.我能找到的最好的是这里的量词部分,其中规定:

\d? Optional digit (one or none).
\d* Eat as many digits as possible (but none if necessary)
\d+ Eat as many digits …
Run Code Online (Sandbox Code Playgroud)

regex

4
推荐指数
1
解决办法
3287
查看次数

标签 统计

regex ×2

.net ×1

c# ×1