Solved

Reqular Expression With Carriage Returns

Posted on 2015-01-24
10
80 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 74

Expert Comment

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

e.g.

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

Open in new window

0
 

Author Comment

by:David Bach
Comment Utility
Greetings kaufmed;

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


Thank you for your time though.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
\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
 

Author Comment

by:David Bach
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:David Bach
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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 74

Accepted Solution

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
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.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now