我有以下文本"The other one there, the blithe one."
我想写一个正则表达式来匹配"The"
或"the"
的出现次数。我的解决方案是[^A-za-z][Tt]he[^A-za-z]
。当我将这个输入到在线正则表达式工具中时,我只能在“the”上找到匹配。我的代码是正确还是不正确?如果不正确,找到文本中"The"
或"the"
的匹配项的解决方案是什么。提前感谢您提供任何解决方案,建议或解释。正文中的“The”或“the”正则表达式“The other one there,the blithe one”。
0
A
回答
4
3
没有与正则表达式匹配整个单词的一个更好的方式 - 你可以用“单词边界”锚,像这样:
\b[Tt]he\b
你的正则表达式是不正确的,因为它不会匹配The
在输入的开头或结尾,其中[^A-za-z]
表达式与匹配The
或the
的部分之前没有任何匹配。另一方面,词边界锚是“零宽度”(即它们不捕获任何东西),这允许在输入的开始或结束时匹配表达式。
相关问题
- 1. <a href=''> not working on the other pages
- 2. The Rails Way - Namespaces
- 3. Arrowization the store comonad
- 4. Image of the circle
- 5. Imroving the javascript code
- 6. Perforce in the Cloud
- 7. 'the length not know'inano.function
- 8. DOMNodeInserted in the IE
- 9. Lexing The VHDL'(tick)Token
- 10. Swift:Alphabetize List忽略“The”
- 11. Rest to the Object-URL
- 12. Bash Shell - The:命令
- 13. Metacircular evaluation,implementation the environment
- 14. GPUImageMovie not respect the imageOrientation
- 15. The C Programming Language 1.9
- 16. Stripe not being the cards
- 17. Eventbrite at the-door API
- 18. The ServletServerCache和ClassNotFoundException mysocket
- 19. 正则表达式在Virginia Woolf的小说The Waves中捕获对话框?
- 20. “The Little Schemer”中的示例
- 21. 在wordpress页脚上删除“Get the smart with the WordPress Wordpress Theme”
- 22. ItextSharp-Exception in the reader initialization“The document has no page root”
- 23. SELECT some column and count the rows in the same query
- 24. listview item with clickable subview sometime can not pass the click event to the item's subview
- 25. Learn Python The Hard Way ex35
- 26. 替代<a href="#"> when the anchor tag only triggers a jQuery action without redirecting the user?
- 27. STL Vectors and the new operator
- 28. Ruby on rails geting to the code
- 29. Java:remove-common-words-method in the API?
- 30. 编辑javascript on the fly