可以在C#中这样做:Regexregex = newRegex(@"]*>[^")
stringcleanedHtml = regex.Replace(html, "")
可是我并不想再写个循环去遍历每条记录,然后保存每条记录,我想在数据库中一步到位,而sql只提供了简单的replace函数,这个函数明显不能达到咱的要求,那就去写一个自定义函数吧。
函数源代码如下:CREATE functiondbo.regexReplace
(@source ntext,--原字符串@regexp varchar(1000),--正则表达式@replace varchar(1000),--替换值@globalReplace bit=1,--是否是全局替换@ignoreCase bit=0 --是否忽略大小写)returnS varchar(1000)AS
begin
declare@hr intege
declare@objRegExp integer
declare@result varchar(5000)exec@hr =sp_OACreate'VBScript.RegExp',@objRegExp OUTPUT
IF@hr 0 begin
exec@hr =sp_OADestroy@objRegExp
returnnullend
exec@hr =sp_OASetProperty@objRegExp,'Pattern',@regexp
IF@hr 0 begin
exec@hr =sp_OADestroy@objRegExp
returnnullend
exec@hr =sp_OASetProperty@objRegExp,'Global',@globalReplace
IF@hr 0 begin
exec@hr =sp_OADestroy@objRegExp
returnnullend
exec@hr =sp_OASetProperty@objRegExp,'IgnoreCase',@ignoreCase
IF@hr 0 begin
exec@hr =sp_OADestroy@objRegExp
returnnullend
exec@hr =sp_OAMethod@objRegExp,'Replace',@result OUTPUT,@source,@replace
IF@hr 0 begin
exec@hr =sp_OADestroy@objRegExp
returnnullend
exec@hr =sp_OADestroy@objRegExp
IF@hr 0 begin
returnnullend
return@result
end
需要注意的是,即使写好了这个函数,也并不能马上使用。执行这个函数时可能会出现以下的错误:Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to procedure 'sys.sp_OACreate' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online.
这是因为未开启Ole Automation Procedures选项,MSDN中的Ole Automation Procedures选项。执行下面的语句开启这个选项:sp_configure'show advanced options',1GO
RECONFIGUREGOsp_configure'Ole Automation Procedures',1GO
RECONFIGUREGO
所有的准备工作都已经做好,那就试验一下吧。
Example1:忽略大小写并替换selectdbo.regexReplace('123456',']*>[^','',1,1)
Example2: 使用贪婪匹配
html代码:
Also Available - Smith &Hogan: Criminal Law Cases &Materials 10th ed
There is, as ever, detailed analysis of the many recent case developments, in particular,
a revision of the chapter dealing with secondary liability and joint enterprise.
调用代码:selectdbo.regexReplace(html,']*>(.|\n)*?','',1,1)
Example3:去除html标签selectdbo.regexReplace('
Key Contact:
Mr Jack, Zhou
General Manager
Mr Adu, Ho
Marketing Director
Overseas Sales
MsWinny, Luo
Sales Manager
Overseas Sales',']*>','',1,0)
Example4:数据库字段值替换updateBooks。
java快速过滤掉某个字符串包含的最长的一个词方法:把敏感词的第一个字符取出来,作为比较对象。遍历整个字符串,如果发现字符跟敏感词第一个字符相同,就从字符串取出跟关键词相同长度的子串比较,如果相同就替换。本算法比较适合敏感词都不长的场合。Java是一门面向对象的编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。1、首先在业务层加判断然后做补全处理。2、其次在条件过滤之后如果个数不足pageSize则pageNum++。
3、最后从下一页拿数据补足这条请求需要的数据,然后再返回即可。