Regular Expression Help please

K

Kerry

Please help.

I need a regular expression that parses a stream of up to 450 characters
into 15 separate strings of up to 30 characters each. The regex must break
at newlines. Ideally, the regex will "word wrap" that is, not break in the
middle of words. I have the following:

(?m:(?:(.)?){1,30}\s\n?){1,15}?

This works well as long as the user leaves at least one whitespace character
at the end. Without this, the last word is omitted from the match.

How might this be altered to avoid missing the last word?
 
K

Kerry

Thank you for the suggestion, but that actually ruins the word wrap by not
forcing breaks at whitespace.

Any other suggestions?

Anyone?
 




| Thank you for the suggestion, but that actually ruins the word wrap by not
| forcing breaks at whitespace.
|
| Any other suggestions?

perhaps if i knew more...are you splitting this with a regex or wanting
matches? you're just shooting for a way to do word wrapping, right?
 




| Any other suggestions?

sorry...i didn't look close enough at your regex...here's the fix:

(?m:(?:(.)?){1,30}[\s\n]?){1,15}?

it does NOT handle wrapping words...this one is the work horse and can be
used in conjunction with another to handle it.

good luck.
 
K

Kerry

I'm not shooting for word wrapping -per se.

My users enter data into a multiline textbox that is 30 columns by 15 rows
(ASP.Net web form). As they are entering the data, the textbox presentation
wraps the input string for the user. When submitted, the value of the input
string is one long string (no line breaks unless the user purposefully added
a carriage return). I need to split this string into up to 15 strings, up
to 30 characters each because that is the format expected for downstream
processing by a legacy system. If I can acheive this, I'd like to use the
same string in a regular expression validator, to ensure that the user's
entry matches the pattern that can be split and sent to the legacy system.

Each match should terminate at a newline (if present) or whitespace (if
not), or at the end of the input string (default case). The exp I proposed
works well as long as the last character is whitespace. I need to modify
this (or choose another approach) to handle the last condition, (end of the
input string without whitespace terminator).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top