Solved

Reqular Expression With Carriage Returns

Posted on 2015-01-24
10
83 Views
Last Modified: 2015-01-24
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
Comment
Question by:David Bach
  • 5
  • 5
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40568397
Add "\r" to your pattern.

e.g.

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

Open in new window

0
 

Author Comment

by:David Bach
ID: 40568438
Greetings kaufmed;

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


Thank you for your time though.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40568457
\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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Author Comment

by:David Bach
ID: 40568512
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40568533
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
 

Author Comment

by:David Bach
ID: 40568543
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40568547
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
 

Author Comment

by:David Bach
ID: 40568571
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
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40568602
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
 

Author Comment

by:David Bach
ID: 40568737
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: 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question