File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Pattern Error while using RegEx Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Pattern Error while using RegEx" Watch "Pattern Error while using RegEx" New topic

Pattern Error while using RegEx

pk anoop

Joined: Jun 11, 2009
Posts: 7

Hi All,

I am stuck up with a problem while using Regular Expression.
My requirement is : split a long string into maximum size of 125 letters and then insert a line break in between them.
while splitting, it shouldn't split between the words. in short, i want to split a string into small strings whose length is 125 or at the end of word before 125th letter. Hope i didnt confused

i used one regexp to solve this, and believe me am an absolute zero in this.
i just got one code and copy pasted ;-)

this is my code, and it's working perfectly unless the starting string ends with a full stop(.).
In that case it is giving an error like : No match found.

Please help.

Anoop P K
David Newton

Joined: Sep 29, 2008
Posts: 12617

I'm not even sure I'd use a regex for this, honestly.
pk anoop

Joined: Jun 11, 2009
Posts: 7
i want to do it with optimum performance and just am eager about this regular expression also.
Otherwise how will you do it?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19541

I'd go for a simple loop. For instance:

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Pattern Error while using RegEx
Similar Threads
Text search and replacement using nio
java.util.regex package
Java regex?
reverse the text file and write
Large Numbers