Regular Expression for {

S

scifluent

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!
 
S

SadRed

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!

String[] splitLine = input.split(",\\{"); // regex engine gets ",\{"
 
D

Daniel Pitts

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!

"\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.
 
L

Lars Enderin

Daniel Pitts skrev:
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!

"\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 :)

You can often use [] to quote a special character: ",[{]".
 
S

scifluent

Thank you for all of your suggestions, both verbose and terse! I am
back on track!
 

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
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top