开发者

how to match text limiting it with not condition

I have one problem in understanding regex

For example i have following text:

To ask Jack the Daniels, John the Ripper, whether, they will go out.

And I want to match this part - Jack the Daniels, John the Ripper, it ends with comma and lowercase letters after it (, [a-z])*

When I match it with this regex:

'To ask (?P<addressee>[A-Za-z,\s]*), [a-z]'

I get following result:

Jack the Daniels, John the Ripper, whether

So question is can I use not condition inside parenthesis? Something like this, but it not works for me:

'To ask (?P<addressee>[A-Za-z,\s]*(^, [a-z]*)), [a-开发者_开发技巧z]'

----EDIT

Seems if i will match it with something like this: '(\W[A-Z].*?),' and use preg_match_all I will get what I want, but text can be like following too:

To ask Jack the Daniels, John the Ripper, whether, they will go out with Joe the Man, or me.

And I will match Joe the Man too, which I don't want to. Do I need to use before condition to check is there a (, [a-z]) before match?

Following don't work, how to correct it?

'(?<!(, [a-z]))(\W[A-Z].*?),'


Try with:

'(\W[A-Z].*?),'

Also tested @www.spaweditor.com

-- EDIT

With '\W([A-Z].*?),\W[a-z]' and preg_match you will capture first result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜