I need a RegEx pattern which matches from "where" to the end of the line (\n
). For example, these would match:
我需要一个RegEx模式,该模式匹配从“where”到行尾(\n)。例如,它们会匹配:
"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".
所以基本上,模式必须以“where”开头,以一个新行字符“\n”结束。
EDIT: RegEx pattern will be used in a Ruby (on Rails) project...
编辑:RegEx模式将在Ruby (on Rails)项目中使用……
2 个解决方案
#1
1
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.
$是行结束。我是大小写不敏感的人。
#2
0
\bwhere\s(.*)$ The ()
group what the predicate so you can extract it.
在where\s(.*)$ $()组中使用谓词,这样您就可以提取它。
#1
1
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.
$是行结束。我是大小写不敏感的人。
#2
0
\bwhere\s(.*)$ The ()
group what the predicate so you can extract it.
在where\s(.*)$ $()组中使用谓词,这样您就可以提取它。