![]() |
Problem in pattern matching special characters
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.getJDOM Value(DataStreamTra nsforms.java:606) at com.emc.gvs.basetypes.IOFValidationModule_Main.val idate(IOFValidation Module_Main.java:29) at TesterClass.main(TesterClass.java:45) How to solve this problem? |
Re: Problem in pattern matching special characters
anshul wrote: > 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 } 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.getJDOM Value(DataStreamTra > nsforms.java:606) > at > com.emc.gvs.basetypes.IOFValidationModule_Main.val idate(IOFValidation > Module_Main.java:29) > at TesterClass.main(TesterClass.java:45) > > > How to solve this problem? |
Re: Problem in pattern matching special characters
castillo.bryan@gmail.com wrote:
> anshul wrote: >> 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 } > > Pattern pacxFTPF11 = Pattern.compile("`|<|>|\\{|\\}|;|\"|\\|"); "[`<>{};\"|]" ? - Lew |
| All times are GMT. The time now is 08:03 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.