我是RegExp的新手。我想做的是:
我有这个原始查询条件。
var strQuery = "AND i.CreatedDate BETWEEN CAST('01/01/2014' AS Date) " +
"AND DATEADD(Day, 1, CAST('01/01/2015' AS DATE) ) " +
"AND e.User_ID IN (-1, 1234, 3433, 9999) " +
"AND i.STATUS IN ('Completed') AND o.Type IN ('Production') "
现在,查找字符串“e.User_ID IN(”然后用新ID字符串替换括号()之间的任何内容。例如。
var newUserIDs = "8888, 3333, 4444"
// After search and replace using RegExp.
var strQuery = "AND i.CreatedDate BETWEEN CAST('01/01/2014' AS Date) " +
"AND DATEADD(Day, 1, CAST('01/01/2015' AS DATE) ) " +
"AND e.User_ID IN (8888, 3333, 4444) " +
"AND i.STATUS IN ('Completed') AND o.Type IN ('Production') "
请帮忙。如果我不清楚,因为我对此不熟悉,请告诉我。 提前谢谢。
答案 0 :(得分:1)
你可以简单地连接这样。
var newUserIDs = "8888, 3333, 4444"
// After search and replace using RegExp.
var strQuery = "AND i.CreatedDate BETWEEN CAST('01/01/2014' AS Date) " +
"AND DATEADD(Day, 1, CAST('01/01/2015' AS DATE) ) " +
"AND e.User_ID IN (" + newUserIDs + ") " +
"AND i.STATUS IN ('Completed') AND o.Type IN ('Production') "
alert(strQuery);
毕竟它只是一个字符串。
答案 1 :(得分:1)
使用regexp就像这样:
/assets

您正在搜索您的提示,然后是括号括起来的[]之间的任何字符中的0个或更多。