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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

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

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :WPF

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!

View Complete Post

More Related Resource Links

pls help, using string, that will put all ***** in the middle of a word..ex. hap*****py


pls help, using string, that will put all ***** in the middle of a word..

ex. hap*****py 


Capture and pass "abc\xyz" as a string into my WCF method

Hi All, I am trying to implement WCF Method where client has to pass like "abc\xyz" as a string i have to capture it and pass to my method. I am not able to do it. In our application we can split the string  and we can do what ever we can do . but string comes from client site so who do i capture into my method. I am very much new in WCF. Could u please help me. Thanks Shekhar  

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

Capturing data in a string

I want to capture data in a string Ex.  I want the user to pass a comma delimetted string '67282,98272,7282,09282,6272,82728" I want to be able to capture the date seperated by commas  67282 98272 7282 09282 6272 82728 I can than store this data in a table in memary or manipulate it in some way. In VB we have the split function. Is ther a function in SQl 2005 that will allow this or does someomeone have some code example to do this or should I use VB .Net and the CLR to capture this? Thanks!!!    

Capture query string value in javascript in aspx page


I have a simple problem that I cannot remember how to solve.  I am sure it is very easy.  Following is my code:

<asp:Image id="btnAddNew" runat="server" ImageUrl="~/images/btnAdd.png" OnClick="javascript:window.open('DetailLocation.aspx?projectID=&locationID=','newWindow','width=600,height=600,scrollbars=yes');" />

In the OnClick event I have embeded a javascript function that works as expected. However, I need to embed a querystring value into the javascript function variable:


I thought I could just embed <%=Request("projectID") %> in there, but the compiler does not like it. 

Thanks in Advance.



Trying to prevent a match if string contains X

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.


Problem extracting the middle characters of a text string


I need to extract a portion of text from one field and put it in another field and I am having trouble with the syntex.  I am doing this with an sql select statement in asp.net. 

I can select the left most characters of the field (SELECT  BatchNumber, LEFT(BatchNumber, 3) AS Expr1 FROM  DonorHistory) or the right most characters of the field (SELECT BatchNumber, RIGHT(BatchNumber, 3) AS Expr1 FROM DonorHistory) but I cannot select characters from the middle of the field.  I expected that to be able to use a statements such as "SELECT BatchNumber, mid(BatchNumber, 3, 2) AS Expr1 FROM DonorHistory" but this statement gives me an error.  I also tried using middle in place of mid but that did not work either.

What am I doing wrong?





Exception Handling: StackFrame Capture not capturing last level method call in release mode


I am trying print the exception details frame by frame along with other debug info (code below). In the code as you can see the DummyCall3 throws and ApplicationException and the expectation is that the stack trace will have information regarding DummyCall3. Below are the behavior I am getting with .NET 4.

  • Using the "Debug" build, when I run it, I get expected results (DummyCall3 > DummyCall2 > DummyCall > RunTest)
  • Using the "Release" build however, the DummyCall3 method is somehow missing from the stack trace. Now I only get (DummyCall2 > DummyCall > RunTest)
  • I add a dummy statement in the DummCall3 method before I throw the exception, and rerun using "Release" mode and now it works as expected with strack trace info (DummyCall3 > DummyCall2 > DummyCall > RunTest)
  • If I switch the framework version to .NET 3.5 it works as expected in both Release and Debug modes?

I would like to know if this behavior is by design or a bug? if it is by design, what was the reasoning behind it. Appreciate any input on this.


  class StackFrameTest
    public void RunTest()

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





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

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?


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.
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