2

我在 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 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)
4

1 回答 1

4

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

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

String expression = "A(?=B)"; // only matches B if it follows an A
于 2012-07-21T16:25:34.023 回答