• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 92
  • Last Modified:

Reqular Expression With Carriage Returns

Greetings;

I'm using the follow regular expressions within an ASP.NET environment:
^[a-zA-Z0-9 \"\—`\:\&)\-“\”\'\’/\.,]+$

Open in new window

I need to be able to accept carriage return combinations or characters.

I would like to know how to alter my regular expression to accept carriage returns (Windows, Macintosh, UNIX, etc.)


Much thanks ...
0
David Bach
Asked:
David Bach
  • 5
  • 5
1 Solution
 
käµfm³d 👽Commented:
Add "\r" to your pattern.

e.g.

^[a-zA-Z0-9 \"\—`\:\&)\-“\”\'\’/\.,\r]+$

Open in new window

0
 
David BachAuthor Commented:
Greetings kaufmed;

Using ASP.NET, adding the \r does not resolve carriage returns.


Thank you for your time though.
0
 
käµfm³d 👽Commented:
\r represents a carriage return. Period. There's no other character to represent such. So, my question to you would be:  Have you inspected the data crossing the wire? Is it really a carriage return?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
David BachAuthor Commented:
Greetings kaufmed;

My apologies. I omitted crucial information.

I am using an asp:RegularExpressionValidator, setting the ValidationExpression to the regular expression I mentioned.

Is there a way to set the RegexOptions attribute for this control as well to RegexOptions.Multiline?


Much thanks ...
0
 
käµfm³d 👽Commented:
Multi-line has no bearing on whether or not you can enter a carriage return. Multi-line changes the behavior of ^ and $.

Just to be clear:  Are we talking about carriage returns or newlines?
0
 
David BachAuthor Commented:
Hi Kaufmed;

I am encountering hex ODOA characters in an asp:TextBox with the TextMode="MultiLine" value set.

I hope this helps.

Much thanks ...
0
 
käµfm³d 👽Commented:
0D0A is a carriage return/newline combination, not simply a carriage return. You need to account for both characters:

^[a-zA-Z0-9 \"\—`\:\&)\-“\”\'\’/\.,\r\n]+$

Open in new window

0
 
David BachAuthor Commented:
Hi Kaufmed;

I agree with your assessment, however, without the ability to set regex options for the asp:RegularExpressionValidator I do not see how the regular expression will work even with the \r and \n characters (which I have tried to no avail).

Using RegexBuddy by JustGreat Software, the regular expression only works if the multiline option is set, otherwise there is no match.

Perhaps there is a different character other than the ^ and $ at the beginning and end of the regular expression I need to use.


Much thanks ...
0
 
käµfm³d 👽Commented:
Ordinarily you can use multi-line to alter the behavior of ^ and $ in a regex. HOWEVER, the RegularExpressionValidator has an internal check to see that the match consists of the entire string, not just part of it. Multi-line has no benefit inside of a REV, and truthfully doesn't do anything.

And again, you don't need mult-line here.

e.g.

 Screenshot Markup
0
 
David BachAuthor Commented:
Hi kaufmed;

Perhaps we both missed this. I know I did.

The ValidationExpression in your latest example replaced the quotation mark with &quote;. When I changed my regular expression in the same way all worked as expected.


Much thanks for your patience and diligence, Kaufmed.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now