I'm having trouble creating a regular expression. I have an html form that contains the <textarea></textarea> tags. When the form is submitted, I capture the output of the <textarea> and write it to a .txt file. For some reason, unknown to me, carriage returns and whitespaces are mysteriously added to the output of the <textarea> on every post, even when the <textarea> is not edited, so the output of the textarea grows with each submission of the form.
I would like to strip the added carriage returns that always have varying number of whitespaces after them, so I need one regular expression that would match all of the following, where a whitespaces (eg \s) are represented by dots, and the carriage returns (eg \r) is represented as CR, for example:
here is a carriage return followed by four whitespaces:
$the_string="CR....";
Here is a carriage return followed by seven whitespaces.
$the_string="CR.......";
Here is a carriage return followed by eleven whitespaces.
$the_string="CR...........";
I've tried many regular expressions but nothing seems to work, unless I include a specific number of whitespaces in the regular expression like $string =~ s/\r\s\s\s\s/\r/g, but the string always begins with a CR followed by different numbers of whitespaces, depending on how many time the form has been submitted.
Here is the latest regular expression I've tried:
$the_string =~ s/(\r|\s+)\b/\r/g;
Here I was hoping to match, anywhere in the string, all CR(s) that are followed by an unknown number of whitespaces, and replace the matches with a single CR.
Any help would be greatly appreciated.
Regards,
LelandJ
Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
I would like to strip the added carriage returns that always have varying number of whitespaces after them, so I need one regular expression that would match all of the following, where a whitespaces (eg \s) are represented by dots, and the carriage returns (eg \r) is represented as CR, for example:
here is a carriage return followed by four whitespaces:
$the_string="CR....";
Here is a carriage return followed by seven whitespaces.
$the_string="CR.......";
Here is a carriage return followed by eleven whitespaces.
$the_string="CR...........";
I've tried many regular expressions but nothing seems to work, unless I include a specific number of whitespaces in the regular expression like $string =~ s/\r\s\s\s\s/\r/g, but the string always begins with a CR followed by different numbers of whitespaces, depending on how many time the form has been submitted.
Here is the latest regular expression I've tried:
$the_string =~ s/(\r|\s+)\b/\r/g;
Here I was hoping to match, anywhere in the string, all CR(s) that are followed by an unknown number of whitespaces, and replace the matches with a single CR.
Any help would be greatly appreciated.
Regards,
LelandJ
Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox