2017-04-03 75 views
-4
下面

如何用Java編寫的正則表達式表達

  1. 100 RS -disallowed
  2. 允許和在正則表達式不允許表達
  3. 百年-allowed
  4. RS 100 -disallwoed

在上面的表達式可以給出不允許的詞,如「rs | RS |盧比」

+0

'if(str.contains(「rs | RS | rupee」)){/ * disallow * /}' – XtremeBaumer

+1

你到目前爲止試過了什麼?你卡在哪裏? – MrSmith42

+0

我已經嘗試過模式r = Pattern.compile(Rs | RS | fuck | rupee | rs); \t \t Matcher m = r.matcher(100 rs); \t \t return m.find();但在這種情況下,它不允許'100年'也 – sachin10

回答

1

您可以使用java.util.regex.Pattern類和java.util.regex.Matcher類似打擊。

String str = "targetStr"; 
String regEx = "regEx"; 
Pattern pattern = Pattern.compile(regEx); 
Matcher matcher = pattern.matcher(str); 
+0

我用這與regEx =「Rs | RS |他媽的|盧比| rs」;但它不允許100年也'rs'b'coz。 – sachin10

+0

我也嘗試過使用String regEx =「^(?! Rs $ | RS $ | fuck $ | rupee $ | rs $)」;但它允許我需要阻止的'100 rs'和'rs 100'。 – sachin10

0

正則表達式圖案將是:

字符串configSting = 「RS | RS | RS |盧比」;字符串 regEx =「(?:^ |(?< = [^ a-zA-Z]))(」+ configSting +「)(?:(?= [^ a-zA-Z])) Pattern stringPattern = Pattern.compile(regEx);