开发者

Why is this regex behaving like this?

I have a regular expression here, and I want it to return only users, comments, and posts. However, even 开发者_如何学Pythonthough I have \s, whitespace, in my negative character set, it still is extracting a match from it. Why is this?


It seems did not match any space character, but just a position, since * will match a string with length 0. Try ([^\s().,]+)


It's matching empty positions (zero-length strings), not spaces, and that's because you're using the star (zero or more) rather than the plus (one or more) repetition modifier. ([^.,()\s]+) returns only "users", "comments" and "posts".


yes its because of the + Here is a powered regexp that extract each parameter $1 = user $2 = comment $3 = post

(([^.,()\s]+).(([^.,()\s]+), ([^.,()\s]+)))

but of course, cant exists comments or posts with those reserverd characters

or this its a more flexible example (([^.,()\s]+).(\s*([^.,()\s]+)\s*,\s*([^.,()\s]+)\s*))

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜