Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

Problem in pattern matching special characters

Thread view: 
anshul - 21 Dec 2006 01:27 GMT
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?
castillo.bryan@gmail.com - 21 Dec 2006 05:33 GMT
> Hi,
> I need to match the following characters in a pattern ` < >  { }  ; "
[quoted text clipped - 3 lines]
> Like this:
> Pattern pacxFTPF11 = Pattern.compile("`|<|>|{|}|;|\"|\\|");

Try this: (you have to escape { and }

Pattern pacxFTPF11 = Pattern.compile("`|<|>|\\{|\\}|;|\"|\\|");

> Matcher macxFTPF11 = pacxFTPF11.matcher(acxFTPFile);
>
[quoted text clipped - 21 lines]
>
> How to solve this problem?
Lew - 21 Dec 2006 06:52 GMT
>> Hi,
>> I need to match the following characters in a pattern ` < >  { }  ; "
[quoted text clipped - 7 lines]
>
>  Pattern pacxFTPF11 = Pattern.compile("`|<|>|\\{|\\}|;|\"|\\|");

"[`<>{};\"|]"
?

- Lew


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.