Splitting an escaped string

E

Enter The

How do I split an escaped string?

For example, I have a string where \ is the escape character.

So if the string is:

abc def\:ghf : xyz

and I split it by :,

I'd want to return the strings

"abc def\:ghf"and "xyz".

Not "abc def\", "ghf" and "xyz".

Thanks,

Enter
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Enter said:
How do I split an escaped string?

For example, I have a string where \ is the escape character.

So if the string is:

abc def\:ghf : xyz

and I split it by :,

I'd want to return the strings

"abc def\:ghf"and "xyz".

Not "abc def\", "ghf" and "xyz".

String s = "abc def\\:ghf : xyz";
String[] parts = s.split("(?<!\\\\):");

seems to work.

Arne
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top