Edward J. Stembler
Edward J. Stembler

Reputation: 2042

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...

Upvotes: 0

Views: 108

Answers (2)

user177800
user177800

Reputation:

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

Upvotes: 0

Jason McCreary
Jason McCreary

Reputation: 72971

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.

Upvotes: 1

Related Questions