如何在正则表达式中写可选单词? [英] How to write optional word in Regular Expression?
本文介绍了如何在正则表达式中写可选单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个Java正则表达式来识别以下模式.
abc def the ghi
和abc def ghi
I want to write a java Regular expression that recognises the following patterns.
abc def the ghi
and abc def ghi
我尝试过:
abc def (the)? ghi
但是,它无法识别第二种模式.我哪里出错了?
But, it is not recognizing the second pattern.Where am I going wrong?
推荐答案
abc def (the )?ghi
^^
删除多余的space
这篇关于如何在正则表达式中写可选单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文