[英]How do i replace following in notepad++ regex?
I have SQL insert statement. 我有SQL插入语句。 One of values is date which i need to replace. 值之一是我需要替换的日期。
Insert into table (column_a, column_b) values ('test',to_date('01/DEC/15','DD/MON/RR'));
I have over 1000s of Insert SQL statement as above. 我有超过1000的上述插入SQL语句。
I want to replace value of column_b which has format "to_date('01/DEC/15','DD/MON/RR')"
date can change within function. 我想替换格式为"to_date('01/DEC/15','DD/MON/RR')"
的column_b值,该日期可以在函数内更改。 I want to replace column_b value with "SYSDATE"
for all rows. 我想将所有行的column_b值替换为"SYSDATE"
。
I tried following nothing is working. 我尝试不执行任何操作。
^[to_date].*
/to_date([a-zA-Z0-9/,'])+/
/^to_date(.*$/
Can someone help? 有人可以帮忙吗?
Insert into table (column_a, column_b) values ('test',to_date('01/DEC/15','DD/MON/RR')); 插入表(column_a,column_b)值('test',to_date('01 / DEC / 15','DD / MON / RR')); to_date(' 至今('
If syntax of to_date function is correct throughout, this will satisfy your requirements: 如果to_date函数的语法始终正确,则可以满足您的要求:
to_date\([^)]+\)
What this regular expression means: 此正则表达式的含义:
to_date
← find this literal string to_date
←找到这个文字字符串 \\(
← followed by an open parenthesis. The backslash is an "escape character." You need to "escape the parenthesis," because parentheses are special characters in regex used to define a group. \\(
←,后跟一个开放的括号。反斜杠是一个“转义字符”。您需要“转义该括号”,因为括号是正则表达式中用于定义组的特殊字符。 [^)]
← followed by 1 or more of any character except a closing parenthesis. [^)]
←后跟一个或多个任意字符, 但右括号除外 。 The brackets indicate a character set []
. 方括号表示字符集[]
。 The leading caret ^
negates the character set ("not this set"). 前导插入符号^
否定了字符集(“不是此字符集”)。 \\)
← followed by a closing parenthesis. \\)
←,后接右括号。 Again, since this is meant to be a literal parenthesis and not the closing parenthesis of a regex group, the character must be escaped. 同样,由于这是一个字面括号,而不是正则表达式组的右括号,因此必须对字符进行转义。 Answer 回答
to_date\(.+?\)
This matches... 这匹配...
to_date(
文字to_date(
.+?
- a non-greedy / lazy match for one or more of any character -任何一个或多个字符的非贪婪/惰性匹配 )
文字)
Here's where you were going wrong 这就是你要去的地方
^
- this is the "start of string" anchor. ^
任何用法-这是“字符串开始”锚点。 Since the string you're looking for never appears at the start, this will never match. 由于您要查找的字符串永远不会出现在开头,因此永远不会匹配。 [to_date].*
- this is a character class matching zero-or-more of the characters inside, ie "t", "o", "_", "d", "a", or "e" [to_date].*
-这是一个匹配零个或多个字符的字符类,即“ t”,“ o”,“ _”,“ d”,“ a”或“ e” to_date([a-zA-Z0-9/,'])+
- the parentheses here aren't escaped so instead of matching literal (
and )
, they form a capture group for the character class inside. to_date([a-zA-Z0-9/,'])+
-此处的括号不会转义,因此不是匹配文字(
和)
,而是形成了内部字符类的捕获组。 Since you missed the literal parentheses, this will never match. 由于您错过了文字括号,因此将永远不会匹配。 to_date(.*$
- this is an invalid expression as you're missing the closing )
for the capture group to_date(.*$
-这是一个无效的表达式,因为您缺少捕获组的结尾)
In my opinion, in this situation, the simplest regular expression is: 我认为,在这种情况下, 最简单的正则表达式为:
to_date.{25}
This expression means literal string "to_date" and 25 characters after it . 该表达式表示文字字符串“ to_date”及其后的25个字符 。
It will work. 它会工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.