gpt4 book ai didi

regex - 将 Android 正则表达式移植到 BlackBerry 正则表达式不起作用

转载 作者:行者123 更新时间:2023-12-04 18:16:24 25 4
gpt4 key购买 nike

我在 Android 中使用此代码来验证密码。但是现在想在BB中使用这个表达式。但它不起作用并给出异常

这是安卓代码

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public static boolean isUserPassValid(String userPass) {

boolean isValid = false;
try {
String expression = "^.*(?=.{5,30})(?=.*\\d)(?=.*[a-zA-z]).*";
CharSequence inputStr = userPass;

Pattern pattern = Pattern.compile(expression,
Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
} catch (Exception e) {
Log.e(TAG, "isUserPassValid Message = " + e.toString());
e.printStackTrace();
}
return isValid;
}

这是我现在尝试在 Java 中验证的 BB 代码
import com.sun.org.apache.regexp.internal.RE;


public class Test {

/**
* @param args
*/
public static void main(String[] args) {
isValidPassword("Arsla");

}

public static boolean isValidPassword(String text) {
System.out.println(" password for varefication is : " + text);
boolean isValid = false;
String expression = "^.*(?=.{5,30})(?=.*\\d)(?=.*[a-zA-z]).*$";
String username = text;
RE regx = new RE(expression);
try {
isValid = regx.match(username);
System.out.println("password msps to the re " + isValid);

} catch (Exception e) {

}
return isValid;
}

}

这是异常(exception)
Exception in thread "main" com.sun.org.apache.regexp.internal.RESyntaxException: Syntax error: Missing operand to closure
at com.sun.org.apache.regexp.internal.RECompiler.syntaxError(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.terminal(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.closure(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.branch(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.expr(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.terminal(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.closure(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.branch(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.expr(Unknown Source)
at com.sun.org.apache.regexp.internal.RECompiler.compile(Unknown Source)
at com.sun.org.apache.regexp.internal.RE.<init>(Unknown Source)
at com.sun.org.apache.regexp.internal.RE.<init>(Unknown Source)
at Test.isValidPassword(Test.java:19)
at Test.main(Test.java:10)

最佳答案

也许 BB 正则表达式实现不支持环顾四周。

尝试在 android 和 blackberry 上执行一个简单的环视示例,看看它是否
作品。例如

String expression = "A(?=B)"; // only matches B if it follows an A

关于regex - 将 Android 正则表达式移植到 BlackBerry 正则表达式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11593594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com