.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

Trying to prevent a match if string contains X

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :.NET Framework
I'm relatively new to RegEx and trying to wrap my head around the whole thing. I'm sure others would need to accomplish what I'm trying, but I can't seem to use the right search terms to find anything.

I'm using a RegEx to either Match or Not Match if the string contains certain words/characters.

Example1:  "Do Not Match" vs "Match"

I want to match each string on the word Match. However, since the first string contains "Do Not" I don't want to match on it at all.

Example2:  "Some Example [Text]" vs "Some Example Text"

Since the first string contains [] I do not want a match at all.

Hopefully I've got my point across. I've tried numerous things and all have failed. Conditionals, LookAheads, LookBehinds, etc. I don't know enough to make this thing work the way I want. I will appreciate any assistance.


View Complete Post

More Related Resource Links

How do I prevent the largest possible match on a string?


Here's the string

(X) </a><b>string1</b>, <a href="testing 1-2-3">string2</a> (string3)

Here's my regular expression:


which i think means:

\(  match an open parenthesis

([\s,\S]{2,}?)   match any space or non-space characters at least two long (inside parenthesis)

\)  match a close parenthesis


I thought specifying {2,} would prevent (X) from being matched, but the problem is, my regular expression matches the open parenthesis starting at the beginning of the string (X) and ending with (string3). 

All I want to capture is (string3)

How can I accomplish this?


Loop until a string match is found

Hi,I have a column in a table which contains a string of data (about 2000 characters in length). this particular column data may have multiple occurances of an Order number. I will have to find out each one of these and insert them as a separate row in another table. I'm not quite sure how to approach this.To make it clear, here's an example:Table_A has column called data_col.data_col has data :********TOP OF DATA***********some text Order# 1111111 some textsome text Order# 2222222 some textsome text Order# 3333333 some textsome more text********BOTTOM OF DATA***********each of these rows will have the header and footer called top of data & bottom of data. So , I was thinking of something like looping through until we hit "Bottom of Data", and get the 3 order#s into a separate tablebut I'm not sure how.Let me know if the question is not clear enough.Thanks

UriTemplate won't match string parameters with slashes


Hello All,

I have a WCF service that takes string parameters in the UriTemplate which contain slashes. For example, I want to setup a UriTemplate like "/items/{itemId}/elements", where the itemId contains slashes.

I tried to use the wildcard, like  "/items/{*itemId}/elements, but using this template chokes the runtime. I learned from this link that it appears to work only when the wildcard appears in last variable is the segment.

I could remove the offending variable (in this case, itemId) from the Uri and add it to the body of the request, but I woul like to avoid it since it would result URLs not very intuitive.

Any help would be greatly appreciated.

Kind regards





How do I match and not capture something in brackets in the middle of a string that I am capturing?


This is my input string:

, a. [the Cat.] Pertaining to the Cat.


This is my regular expression:


(?!^|,) means match the beginning of the string or a comma, negative lookahead

([\s,\S]*?) means match anything

[A-Z] means match a capital letter-- in this case, it was meant to capture 'P' from "Pertaining to..."


This is what I catch:

a. [the


This is what I want to catch:



Some input strings, like the one above, have [some text in brackets] while some input strings do NOT.

If there is bracketed text in the string with a capital letter,

1) how do I prevent the capital letter in the brackets from matching the [A-Z], and

2) how do I not capture the bracketed text?


Thanks for the help!

Regular Expression Match Exact String


I'm looking for a regular expression that satisfies one of the two conditions (Reg Expression OR Exact String Match W/ Underscores) listed below.





Thanks in advance

does static Regex.Match(string input, string pattern, RegexOptions ops) cache ?


in msdn, it is said that static Regex.Match(string input, string pattern) caches for future uses,

but it doesn't say whether static Regex.Match(string input, string pattern, RegexOptions ops) caches.

Then does it cache? Does it help to promote performance at creation?


How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Connestion string create any database server

This links important to how to create connection string to any data base sever.

SQL Connection String

We can learn or know how can we connect the database from our .net. This will help for freshers or .NET beginners!

Built-in Functions - String Functions

String functions let you extract various portions of character strings, change the case of strings, concatenate and reverse strings and perform many other types of manipulations. All built-in string functions are deterministic with the exception of CHARINDEX and PATINDEX

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

highlight string


i am looking for a function that takes two string parameters 

str1 = "hello how are you today mr john"

str2 = "how today"

and in return it shoud highlight the words "how" and "today".

Any ides? I prefer if its possible using reg expression...Thanks

Could some one tell me whats the Problem with this String Manipulation ??? C#.net



I store some values from code behind to a label which is Hidden !

<asp:Label ID="lbl_Hidden" runat="server" Visible = "false"></asp:Label>

and at the page load event i retrieve the value of the label & assign it to a string !

stringvalue = lbl_Hidden.Text;

Now i dont know why this manipulation does'nt work !

I've a character 'A' in the string and i'm unable to replace it with a space !

stringvalue.Replace(A, " ");

Wot do u think abt it ????

extract picture data from a string


dears,advance thanks.can anybdy help to solve my problem which is describing below.

Example- %%D1,100,0,0004[data...][0d0a]

Head - %%D1
Amount of data package -100
The data package No. - 0
Data Length -1024 (0004 (low bit in front, high bit in back) 0004= 0x0400=1024;)

data- Original Picture data -1024(maximum)
Tail -0x0d0a
Data in hex

from the above example i want to extract picture data and need to store in to the sql table.sql table columname is image and datatype is also image.after that i wanted to display this image column to an aspx page.

expecting help asap.

connection string question from a newbie


when publishing  in the webmatrix dialogue it asks for "destination connection string" for my "database.mdf"

I was not sure what it was so I pasted this from my web.config file :

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;User Instance=True

it all published ok, but wont run, so I guess it has somthing to do with this connection string or some kind of configuration issue.

My question is this, What should go in the field for "Destination connection string"

WebMatrix conversion failed when converting from a character string to uniqueidentifier?


I am trying to retrieve xml from a small function in my .cshtml page. Its throwing me an error. This however, runs fine in a console/form environment.

It takes 3 parameters and 1 exception.

myDll.GetXML(year, username, uniqueidentifier, out ex);

When I run this page I get the error, "Conversion failed when converting from a character string to uniqueidentifier."

Or a stack of.

System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting from a character string to uniqueidentifier.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()

   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

   at System.Data.SqlClient.SqlDataReader.get_MetaData()

   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBeha

The number of members in the conceptual type ... does not match with the number of members on the ob



I've added a scalar property to an entity and now ASP.NET Dynamic Data scaffolding throws this error:

The number of members in the conceptual type 'TrainingModel.Users' does not match with the number of members on the object side type 'TrainingModel.Users'. Make sure the number of members are the same.

This happens at the following line in global.asax:
model.RegisterContext(typeof(TrainingModel.TrainingEntities), new ContextConfiguration() { ScaffoldAllTables = true });

Please help!

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend