• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 449
  • Last Modified:

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
0
sudhakar_koundinya
Asked:
sudhakar_koundinya
  • 4
  • 4
  • 2
  • +1
2 Solutions
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now