我正在尝试做一个简单的正则表达式,我想做的就是匹配一个单词的奇异部分,无论它是否有一个s结尾.所以,如果我有以下的话
test
tests
Run Code Online (Sandbox Code Playgroud)
编辑:进一步的例子,我需要这个可能很多单词而不仅仅是那两个
movie
movies
page
pages
time
times
Run Code Online (Sandbox Code Playgroud)
对于所有这些我需要在没有结束的情况下得到单词,但是我找不到一个正则表达式,它总是会抓住第一位而没有结尾的s并且适用于两种情况.
我尝试过以下方法:
([a-zA-Z]+)([s\b]{0,}) - This returns the full word as the first match in both cases
([a-zA-Z]+?)([s\b]{0,}) - This returns 3 different matching groups for both words
([a-zA-Z]+)([s]?) - This returns the full word as the first match in both cases
([a-zA-Z]+)(s\b) - This works for tests but doesn't match test at all
([a-zA-Z]+)(s\b)? - This returns the full word as the first match in both cases
Run Code Online (Sandbox Code Playgroud)
我一直在使用http://gskinner.com/RegExr/来尝试不同的正则表达式. …