开发者

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

开发者 https://www.devze.com 2023-03-07 06:48 出处:网络
I need a RegEx pattern which matches from \"where\" to the end of the line (\\n).For example, these would match:

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

精彩评论

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