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 / April 2007

Tip: Looking for answers? Try searching our database.

Regular Expression for {

Thread view: 
scifluent@gmail.com - 17 Apr 2007 04:10 GMT
String input = "DATA,{23.11,58.25},{23,33,43},{20070705,20070805}";

String[] splitLine = input.split(",{");

doesn't work.  I've tried escaping the {  by using

String[] splitLine = input.split(",\{");

but Eclipse tells me that { is not an escapable character.

Anybody have a suggestion???

Thanks!
SadRed - 17 Apr 2007 04:26 GMT
On Apr 17, 12:10 pm, sciflu...@gmail.com wrote:
> String input = "DATA,{23.11,58.25},{23,33,43},{20070705,20070805}";
>
[quoted text clipped - 9 lines]
>
> Thanks!

String[] splitLine = input.split(",\\{"); // regex engine gets ",\{"
Daniel Pitts - 17 Apr 2007 07:54 GMT
On Apr 16, 8:10 pm, sciflu...@gmail.com wrote:
> String input = "DATA,{23.11,58.25},{23,33,43},{20070705,20070805}";
>
[quoted text clipped - 9 lines]
>
> Thanks!

"\n" create a string with a newline, not a \ and then an n
"\\n" create a string with a single slash, and then an n.
The regex engine needs to parse a string, and it thinks that { is a
special charactor.
To tell the regex enginer that you want the literal {, you have to put
a \ before it in the string.
To get the \ before it in the string, you have to tell the Java
compiler to espace the \
Therefore what you want is "\\{".

Hope this verbose explaination helps cement the concept :-)

Daniel.
Lars Enderin - 17 Apr 2007 09:21 GMT
Daniel Pitts skrev:
> On Apr 16, 8:10 pm, sciflu...@gmail.com wrote:
>> String input = "DATA,{23.11,58.25},{23,33,43},{20070705,20070805}";
[quoted text clipped - 22 lines]
>
> Hope this verbose explaination helps cement the concept :-)

You can often use [] to quote a special character: ",[{]".
scifluent@gmail.com - 17 Apr 2007 17:44 GMT
Thank you for all of your suggestions, both verbose and terse!  I am
back on track!


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



©2009 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.