Problem in pattern matching special characters

A

anshul

Hi,
I need to match the following characters in a pattern ` < > { } ; "
|
I tried to do it through this method : Pattern.compile(pattern1 |
pattern2);
Like this:
Pattern pacxFTPF11 = Pattern.compile("`|<|>|{|}|;|\"|\\|");
Matcher macxFTPF11 = pacxFTPF11.matcher(acxFTPFile);

But it is throwing exceptions:

Exception in thread "main" java.util.regex.PatternSyntaxException:
Illegal repet
ition near index 5
`|<|>|{|}|;|"|\|
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.closure(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at
com.emc.gvs.basetypes.DataStreamTransforms.getJDOMValue(DataStreamTra
nsforms.java:606)
at
com.emc.gvs.basetypes.IOFValidationModule_Main.validate(IOFValidation
Module_Main.java:29)
at TesterClass.main(TesterClass.java:45)


How to solve this problem?
 
C

castillo.bryan

anshul said:
Hi,
I need to match the following characters in a pattern ` < > { } ; "
|
I tried to do it through this method : Pattern.compile(pattern1 |
pattern2);
Like this:
Pattern pacxFTPF11 = Pattern.compile("`|<|>|{|}|;|\"|\\|");

Try this: (you have to escape { and }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top