开发者

How to write regex which matches from a specificed string to the end of a line?

I need a RegEx pattern which matches from "where" to the end of the line (\n). For example, these would match:

"where x = 5\n"
"where x = 5 and y = 6\n"
"where (x = 5) and (y = 6) or (z = 7)\n"

So basically the pattern must start with "where" and end with a new-line character "\n".

EDIT: RegEx pattern will 开发者_运维百科be used in a Ruby (on Rails) project...


You didn't specify your language, but the following is pretty universal:

/\b(WHERE .*)$/i

$ is end of line. i is the flag for case insensitive.


\bwhere\s(.*)$ The () group what the predicate so you can extract it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜