我有以下文本"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. Rafer to the other batch in the same folder in 2008 2008
- 2. HighChart Sparkline Chart with the dynamic data for the table
- 3. 'Stick'image to the right side of the page
- 4. <a href=''> not working on the other pages
- 5. Chaining the ItemsSource DataContext
- 6. Perforce in the Cloud
- 7. AutoGenrate the code
- 8. The Next Palindrome SPOJ
- 9. Remove the trailing]>
- 10. DOMNodeInserted in the IE
- 11. Linux Grep the delta
- 12. 'the length not know'inano.function
- 13. Imroving the javascript code
- 14. Arrowization the store comonad
- 15. Image of the circle
- 16. Html over the Canvas?
- 17. The Rails Way - Namespaces
- 18. abort the right ajax
- 19. Scrapy on the Cloud
- 20. Swift:Alphabetize List忽略「The」
- 21. The C Programming Language 1.9
- 22. Metacircular evaluation,implementation the environment
- 23. Retrief the String with JCheckBox
- 24. .Net RoleProvider without the connectionString
- 25. GPUImageMovie not respect the imageOrientation
- 26. JavaScript alert「the page says」
- 27. Bash Shell - The:命令
- 28. Rest to the Object-URL
- 29. vertical-align:super raise the baseline
- 30. The Nine Tails遊戲