I'm parsing (or attempting to parse) a textarea form submission. I'd like to replace all line breaks with (which is working), and I'd also like to insert a after 30 consecutive non-space characters, if they exist. I was given a suggestion, but without explanation, so I wasn't sure how to implement it. This is what I've got, but it's definitely not right. Any help would be appreciated. Thanks.

OK, I'll try and help ya. Here's the regex I think you need, and I'm assuming here that $text_area is going to be the variable containing the text from you input field.

Code

$text_area =~ s/(?:\r?\n|\s{30,})/\<br\>/g;

The regex is replacing all linereturn sequences, and all sets of spaces (\s) of 30 or more ({30,}) with the \<br\>.

I had to escape the br tag other wise it wouldn't pass through the HTML parser without getting interpreted, but you can take it out of the regex if you want. I don't think it will make a difference. Hope this helps.

Sorry, I should've been clearer. I want to put in a \<br\> after every 30 consecutive non whitespace characters, rather than replace them with a \<br\>. Thought I'd let you know, the reg exp you posted does exactly what you specified.

"Outside of a dog, a book is man's best friend. Inside of a dog, it's too dark to read." - Grouch Marx

Hrm...That really looked like it should work. Unfortunately, it didn't. The line breaks are being replaced just fine, but it's not inserting the \<br\> after 30 characters. I tried it without the expression to replace the line breaks, and it still didn't work. The only thing that's different is the variable name. Any ideas? Thanks.

"Outside of a dog, a book is man's best friend. Inside of a dog, it's too dark to read." - Grouch Marx

I don't know why it's not working other than maybe there isn't an instance where 30 non-whitespace characters occur without at least one occurence of white space. Make sure that you don't have the ?: after the opening paren's in the regex, that would cause it to not store the match in $1. Hmmm what could it be... can you post an example of the text you are parsing? Maybe that would help me.

Got it working. All I had to do was take out the , and it worked great. It was matching against 30 or more characters, rather than just 30 characters. Thanks for all of your help. I really appreciate it.

"Outside of a dog, a book is man's best friend. Inside of a dog, it's too dark to read." - Grouch Marx