2017-04-03 72 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);