Welcome :Guest
Congratulations!!!

Top 5 Contributors of the Month
yasminpriya
Ram
Gaurav Pal
christianasteves

### Regular expression: Replace anything that isn't alphanumeric with a space?

Hi there,I'm writing a function in C# that will clean up a filename that a user might upload.One of the requirements is to replace any character that isn't alphanumeric with a space, but I can't seem to get the regular expression working to do so?I've include my code below, thanks for any help :)// Replace miscellaneous characters with a space inputFilenameRegex = new Regex(@"^[a-zA-Z0-9]"); inputFilename = inputFilenameRegex.Replace(inputFilename, " ");

### Help with a regular expression to skip certain text

I am trying to write a regular expression to find rtf tags with an rtf document so I can strip them out and get the text. And before everyone says to use the RichTextBox control we already used that but this causes problems since this DLL is being converted into an assembly that is used by SQL Server. And since RichTextBox is dependent upon System.Windows.Forms it is causing use problems.

I've never really used regular expressions and found some samples people used to strip the rtf tags. And it works for majority of the tags. But I created an RTF document which looks like the following;

the directory name is c:\par\li\rtf\text stuff in the name.
How does rtf save things with {\par \f2}

Here it is as RTF text;
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Msftedit 5.41.21.2509;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\f0\fs22 the directory name is c:\\par\\li\\rtf\\text stuff in the name.\par
How does rtf save things with \{\\par \\f2\}\par
\par
\par
}


So I need the expression to skip the directory name C:\par\li\rtf\text - and yes I used rtf tags in this directory name to see how it would be handled
I also put in {\rtf and \f2}

The expression I have is the following;

matchpattern =

### Need Regular Expression which allows alphanumeric also & - _ special characters with only one space

Need Regular expression

which allows alphanumeric along with  special characters like &  - _  with only one space between the letters.Special characters should not be at start and at the end of the input string.There should not be 2 successive special characters.

following scenario should accept:

Asd123&ds

AS_df_23 ff-f

Following Scenario should not accept:

_sa&ff

Asd   fff

&-_

_d

only special characters

asdf_

Please suggest solution for above scenario.

### Security Briefs: Regular Expression Denial of Service Attacks and Defenses

Microsoft security expert Bryan Sullivan believes denial-of-service blackmail attacks will become more common as privilege escalation attacks become more difficult to execute. He demonstrates how to protect your apps against regular expression DoS threats.

Bryan Sullivan

MSDN Magazine May 2010

Hello,

### need regular expression to get message body

I have text like this: <tr class="NormalRow_Small"> <td colspan=2>&nbsp;</td> <td colspan=3> </td> </tr> <tr class="NormalRow_Small"> <!--description--> <td colspan="5"> <font size="2">Hi All,<div><!br /></div><div>I'm glad to introduce ...</div><div><!br /></div><div>Actually we already have ... <font size=1>(see link for full text)</font></font><br> <font size="1"> </td> </tr> <tr> <td colspan=5><hr /></td> </tr>   I want to get bold text, please help me.   Thanks, Alex.

### Function count through Regular Expression

Hi, I have a table with varchar(max) column. This column stores all the function calls to application. Example 1    SUM(SALARY); AVG(LEAVES)/COUNT(DAYS); 2    SUM(SALARY)/AVG(SALARY); AVG(LEAVES)/COUNT(DAYS); COUNT(EMPLOYEES); The above output shows the requests of User 1 and 2. User 1 called SUM, AVG and COUNT functions once. User 2 called SUM once and AVG, Count twice. I need to calculate these counts through Regular expression in SQL Server 2005. Following is script for table and data generation: CREATE TABLE [dbo].[UserRequests] (  [UserID] [int] NOT NULL,  [Requests] [varchar](255) NULL ) ON [PRIMARY] insert into [dbo].[UserRequests] values (1, 'SUM(SALARY); AVG(LEAVES)/COUNT(DAYS);') insert into [dbo].[UserRequests] values (2, 'SUM(SALARY)/AVG(SALARY); AVG(LEAVES)/COUNT(DAYS); COUNT(EMPLOYEES);') Any suggestion or idea would be highly admired. PS: if someone has another optimized solution for this problem, kindly suggest that as well. Regards.

### How to read string end with question mark in regular expression?

Hello, I'm facing problem when I read string which is ended by question mark. I use in my code as the following. \"?(?<myfield>[^\"]?.*[^\"?]?)\"? If string is ended by question mark, it's not working. Please help me to solve my problem. Thanks. Co Coe
 Categories:
 ASP.Net Windows Application .NET Framework C# VB.Net ADO.Net Sql Server SharePoint Silverlight Others All