This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 19651

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
Large Numbers
reverse the text file and write
java.util.regex package
Java regex?
Text search and replacement using nio