Regular expression for CRLF-DOT-CRLF

Hello Guys,

What is the regular expression for splitting the String into tokens taking "\r\n.\r\n" as a token seperator and the seperator should still be there in token

thanks
sudhakar
LVL 14
sudhakar_koundinyaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
/(?<=\r\n\,\r\n)/
0
ozoCommented:
Sorry, typo, I meant
/(?<=\r\n\.\r\n)/
0
zzynxSoftware engineerCommented:
This

        String parts[] = "abc\r\n.\r\ndef".split("\r\n[.]\r\n");
        System.out.println("<" + parts[0] + ">");
        System.out.println("<" + parts[1] + ">");

prints out
<abc>
<def>

But I'm not sure about your requirement:
>> the seperator should still be there in token
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

tomboshellCommented:
You don't even need a regular expression for that.   A StringTokenizer is what you need,  and the tokenizer is faster.  Just set it to return the token.

StringTokenizer sTok = new StringTokenizer(string, "\r\n.\r\n", true);
 
0
sudhakar_koundinyaAuthor Commented:
zzynx,

the first part is Okay with me. I am stucked at second point only,

I like to explain the scenario here

We are working on Java -MS Exchange Server Communication Project where I get the emails as xml files. There is a possibilty of getting multiple emails as a single xml file. now using Xalan we are able to transform this xml file into RFC 822/2822 standard emails .

The output what we get here is something similar to outlook express file.

So to split entire transformmed content into individual emails I need to take "\r\n.\r\n" as seperator. But this should be still there in token after splitting the content.

Hope you understand. If not let me know, I will try to explain the our operations using sample examples

Regards
Sudhakar


0
zzynxSoftware engineerCommented:
Of course but
1) the author asked to use split()
2) I quote from the API docs:
    StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.
    It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.
0
zzynxSoftware engineerCommented:
>> But this should be still there in token after splitting the content.
Of course, you could add the token afterwards, no?

        String parts[] = "abc\r\n.\r\ndef".split("\r\n[.]\r\n");
        for (int i=0; i<parts.length-1; i++)
           parts[i] += "\r\n.\r\n";
        System.out.println("<" + parts[0] + ">");
        System.out.println("<" + parts[1] + ">");
0
sudhakar_koundinyaAuthor Commented:
Usage of StringTokenizer is restricted in current project :(
0
ozoCommented:
       String parts[] = "abc\r\n.\r\ndef".split("(?<=\r\n[.]\r\n)");
        System.out.println("<" + parts[0] + ">");
        System.out.println("<" + parts[1] + ">");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSoftware engineerCommented:
That last one seems to be very right.
Do you also know the explanation of that regular expression ozo?
0
ozoCommented:
(?<=X)  X, via zero-width positive lookbehind
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sum
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.