1

I am using this regex expression:

[Ss]([0-9]+)[][ ._-]*[Ee]([0-9]+)([^\\/]*)$

It throws an exception when I am converting into a pattern:

pattern = Pattern.compile(regExp.get(i));


    05-15 11:16:06.914: E/AndroidRuntime(5268): java.util.regex.PatternSyntaxException: Missing closing bracket in character class near index 43:
05-15 11:16:06.914: E/AndroidRuntime(5268): [Ss]([0-9]+)[][ ._-]*[Ee]([0-9]+)([^\\/]*)$
05-15 11:16:06.914: E/AndroidRuntime(5268):                                            ^
05-15 11:16:06.914: E/AndroidRuntime(5268):     at java.util.regex.Pattern.compileImpl(Native Method)
05-15 11:16:06.914: E/AndroidRuntime(5268):     at java.util.regex.Pattern.compile(Pattern.java:400)
05-15 11:16:06.914: E/AndroidRuntime(5268):     at java.util.regex.Pattern.<init>(Pattern.java:383)
05-15 11:16:06.914: E/AndroidRuntime(5268):     at java.util.regex.Pattern.compile(Pattern.java:374)

It works fine when running on a java regex tester. I believe I need to escape some characters here..

1 Answer 1

1

2 issues I see here:

  1. You are using an empty character class []
  2. Backslash needs more escaping

You can use this regex:

[Ss]([0-9]+)[ ._-]*[Ee]([0-9]+)([^\\\\/]*)$
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.