導航:首頁 > 編程語言 > java過濾

java過濾

發布時間:2023-08-07 17:50:37

『壹』 java過濾sql關鍵字的正則替換掉

java過濾sql關鍵字的正則替換掉方法如下:
可以在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 procere 'sys.sp_OACreate' of component 'Ole Automation Proceres' 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 Proceres' by using sp_configure. For more information about enabling 'Ole Automation Proceres', see "Surface Area Configuration" in SQL Server Books Online.
這是因為未開啟Ole Automation Proceres選項,MSDN中的Ole Automation Proceres選項。執行下面的語句開啟這個選項:sp_configure'show advanced options',1;GO
RECONFIGURE;GOsp_configure'Ole Automation Proceres',1;GO
RECONFIGURE;GO
所有的准備工作都已經做好,那就試驗一下吧。
Example1:忽略大小寫並替換selectdbo.regexReplace(�',']*>[^','',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,']*>(.| )*?','',1,1)
Example3:去除html標簽selectdbo.regexReplace('
Key Contact:
Mr Jack, Zhou
General Manager
Mr A, Ho
Marketing Director
Overseas Sales
MsWinny, Luo
Sales Manager
Overseas Sales',']*>','',1,0)
Example4:資料庫欄位值替換updateBooks。

『貳』 JAVA特殊字元過濾方法

|public static String StringFilter(String str) throws PatternSyntaxException {
// 只允許字抄母和數字
// String regEx = "[^襲a-zA-Z0-9]";
// 清除掉所有特殊字元
String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】『;:」「』。,、?]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
return m.replaceAll("").trim();
}

『叄』 java里如何從一個字元串里過濾掉一個子串

用正則表達式,給你一個實例代碼,可以直接運行的。
import java.util.regex.*;
public class Test1 {
public static void main(String[] args) {
//假設你想過濾 "(qemu)"
Pattern p = Pattern.compile("\\(qemu\\)");
//假設你接受到的字元串為"I have a problem (qemu) about this"
String str = "I have a problem (qemu) about this";
Matcher m =p.matcher(str);
//將"(qemu)"用""代替,即過濾掉。
String strnew= m.replaceAll("");
System.out.println(strnew);
}
}

/*如果你想過濾的是"qemu" ,就使用
* Pattern p = Pattern.compile("qemu"); */

『肆』 java中攔截器、過濾器、監聽器都有什麼區別

1、過濾器,是在抄java web中,你傳入的request,response提前過濾掉一些信息,或者提前設置一些參數,然後再傳入servlet或者struts2的。

2、action進行業務邏輯,比如過濾掉非法url(不是login.do的地址請求,如果用戶沒有登陸都過濾掉),或者在傳入servlet或者struts2的action前統一設置字元集,或者去除掉一些非法字元。

3、攔截器,是在面向切面編程的就是在你的service或者一個方法,前調用一個方法,或者在方法後調用一個方法比如動態代理就是攔截器的簡單實現,在你調用方法前列印出字元串(或者做其它業務邏輯的操作),也可以在你調用方法後列印出字元串,甚至在你拋出異常的時候做業務邏輯的操作。

閱讀全文

與java過濾相關的資料

熱點內容
mp3文件多少位元組 瀏覽:261
哪個飾品批發網站好 瀏覽:944
ef資料庫備注 瀏覽:824
iae的配置文件 瀏覽:454
簡單九宮格密碼 瀏覽:89
word2010表格調整行距 瀏覽:960
cad只顯示保存一個plt文件 瀏覽:500
街頭籃球新版本技能兌換券 瀏覽:849
家庭如何做好網路營銷 瀏覽:465
如何設置胎壓監測數據 瀏覽:530
降噪工具 瀏覽:692
obs編程是什麼意思 瀏覽:859
怎麼看c4d打開了多少個文件 瀏覽:792
蘋果銀河高清壁紙 瀏覽:811
怎麼從蘋果電腦垃圾桶找迴文件 瀏覽:771
介面文件不能用action寫嗎 瀏覽:85
svn代碼提交規范 瀏覽:642
在宣讀多少號文件時怎麼讀數字 瀏覽:921
網站中的區域網訪問量是什麼意思 瀏覽:397
蘋果啟動助理識別不到鏡像文件 瀏覽:670

友情鏈接