Saturday, 8 June 2013

Splitting a string greedily

Splitting a string greedily

I would like to split a string on a certain character, say /, but with the first part being matched greedily. In other words, my first approach
\makeatletter
\newcommand{\splitstring}[1]{\@mysplit#1\@nil}
\def\@mysplit#1/#2\@nil{First: #1 -- Second: #2}
\makeatother
on \splitstring{1/2/3} leads to First: 1 – Second: 2/3, whereas I want it to result in First: 1/2 – Second: 3. Is there a simple TeX solution for that?

No comments:

Post a Comment