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

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

Using RegEx, how to find substrings enclosed by a special character

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

Let’s say, special character is: $

Input string: This $abc$ and $def123$ is a test

Desired output:




I tried: @“\$.*?\$"


Got the output as:



View Complete Post

More Related Resource Links

How to find misspelled words with regex

Hi all I need a RegEx that will find a specific word within a long string. The issue is that this word may be misspelled and I need to find it even so. I would like to accept a certain percentage of wrong-ness when looking for the word. Ex. The complete string: Hello, this is my comp/et string to look at The word to search for: complete Let's say that I which to accept a maximum of two wrong letters in the above string, then the RegEx should match the word complete. However, if I only accept 1 wrong letter it shouldn't find it. Ideally the RegEx would also be able to handle whitespaces, and missing letters. Ex: The complete string: Hello, this is my com plee string to look at The word to search for: complete This should match the word as well, even though there is a whitespace between 'm' and 'p' and the letter 'l' is missing. Is this possible at all with RegEx or should I be looking at an alternative way to solve it? Thanks, Tommy

problem to convert special character in export to csv

I am using FIleStream object to write .csv file from dataTable/Dataset.It is working fine. But when i got special character in my DataTable like $, @, # ect. it will convert these convert in encoded form( which can't be readable i.e.  â,¬ etc). FileStream flStream;astrFileName = HttpContext.Current.Server.MapPath("~/files/FtpFiles/Download/") + astrFileName + ".csv";if (File.Exists(astrFileName)){flStream = new FileStream(astrFileName, FileMode.Truncate, FileAccess.Write);}else{flStream = new FileStream(astrFileName, FileMode.Create, FileAccess.Write);}StreamWriter objSw = new StreamWriter(flStream);DataTable objDt = idtInstance;//Get No Of Column in GridView int NoOfColumn = objDt.Columns.Count;//Create Header for (int i = 0; i < NoOfColumn; i++){objSw.Write(objDt.Columns[i]);//check not last column if (i < NoOfColumn - 1){objSw.Write("||");}}objSw.Write(objSw.NewLine);//Create Data foreach (DataRow dr in objDt.Rows){//if (dr["GCMSCaseNumber"].ToString() == "14222")//{// string desc = dr["Updates"].ToString();//}for (int i = 0; i < NoOfColumn; i++){string sData = dr[i].ToString();sData = sData.Replace("<br>", " ");sData = sData.Replace("<br/>", " ");sData = sData.Replace("\n", " ");sData = sData.Replace("\t", "

How to prevent special character encoding when using xslt value in javascript variable

Hi, I've created a dataview and inserting a little bit of javascript. I need to store one of the xslt values into a javascript variable. The problem is that when I get the value into my javascript variable, it is already encoding special characters . for example, instead of "<", I get "&lt;" Am I doing something inaccurate here? I even tried using the javascript unescape() function, but that didn't work. would you be able to advise how to get the xslt value into a javascript variable as it is without having the original data changed? <xsl:template ... ... <SCRIPT type="text/javaScript"> <![CDATA[ ...     var myData = ']]><xsl:value-of select="@sampleData" disable-output-escaping="yes"/><![CDATA['  ;  ... ]]> </SCRIPT> Pman http://www.pmansLab.com/

special character wrongly inserted

I have a gridview with checkbox column.  I loop through all the rows of gridview, if it's checked I enter the second column text into my database.The second column text at one point shows the word  Küche, but when I take that text (in order to insert it in db) it gives me K&#252;cheand that's what I see when I then read it from db.

Best Method to remove special character from string

I am trying to remove the special characters from a string that was entered by the user.  I am not sure the best method to do this.  i can get a foreach of all the characters but what do i check it against?
Christian - developer

Regex: password must contain one number, one letter, and 0 or more special chars


I'm trying to validate a password, and I'm almost there, but need some help finishing it off. Here's what I need:

1) 6-10 characters

2) At least one alpha AND one number

3) The following special chars are allowed (0 or more): !@#$%

Here's what I have:


Passwords that should work: test1ng, abc123, abc1234567, 123abc, abc!123, !@#$%1abcd, !@#$%a9

Passwords that shouldn't work: a, 1, a1, 1$, %, abc!@#, 012345, a1234+, abcde, test*ng, abcde!, !@#$%!, a1234567890, testit!0987, 1abcdefghij

It works on all my test cases, except it allows "a1234567890", "testit!0987", and "1abcdefghij", none of which should be allowed, since they contain more than 10 chars. What am I missing?

Regex to find nested list items

Hi everyone,

I am trying to write a regex parser that will extract links from some html that is generated within our services. Now, extracting items in html I am able to do, but I have n idea how to parse the links from the following, and keep the structure, e.g with the following menu

<ul id="menu">

What I have tried is

<ul id=\"menu\"[^>]*>(.*)</ul>

Now, this does get me the whole menu, but then If I do:


I can get the menu items, BUT, I lose the structure.

So I thought I would be able to extract the LI that contain the UL inside it, but the problem is that using the regex above to extract that LI, I retrieve the following:


Can anyone suggest a way that I can use regex to retrieve this keeping the same structure? or another way of processing these menus and being able to record the structure?



Regular Expression to avoid space and special character



I would like to have an regular expression that does not allow any spaces(before,within,after the word) and alphanumeric characters.

Thanks in advance.



Find the position of a character



we are working with sql server 2005. My xml comes like this:

<ImportResponse xmlns="aaa:import:response:1.0" timestamp="2010-09-24T15:38:40">
<Summary failures="2" successes="3">
 <Message code="-304" level="error">One or more errors have occurred while processing the
  request items
 <Result id="50063,123" success="false">
    <Message code="-1100" level="error">Invalid field format (knect) - The Value fails meets the
     requirements for this field: MaximumLength=9, Precision=0 - {3}
 <Result id="50064,124" success="false">
    <Message code="-1100" level="error">Invalid field format (knect) - The Value fails meets the requirements for this
  field: MaximumLength=9, Precision=0 - {3}


I need to remove the value after ',' from Result element ID attribute. I need to do this

Special Character Translation

I built a view in Designer that's pulling data from a list.  When I deployed the view to SharePoint, I discovered that special characters entered into the list don't display correctly.  For example, "-" is displayed as &#39.  Is there a solution for this translation issue?

SSIS Function for find the Occurance of a character


Please help me to find the solution for the below requirement.

Input data: "AAAA,BBBB,CC" or "A,B,CCC"

I need to check whether the record is having any comma(,) or not. I need to check this this in a "conditional split transformation".

Please let me know which function will help me.

Many Thanks,


How to write storeprocedure update special character in Sql server 2005


Hi All,

I am using Sql Server 2005,My table structure is below.

Create Table ComentTable(id int,coments varchar(4000))

insert into ComentTable values(1,'sanjay I don%27t Know Tamil Language')

insert into ComentTable values(1,'sanjay I don%27t Know Kanar Language')

how to write storeprocedure update coments column replace %27 to &#39;

Program to find first non repetable character in a string without using any buitin function?


Program to find first non repetable character in a string without using any buitin function?

Replace special character with space throughout the database



My requirement is to replace the special characters with space throughout the databse. How can I do this? I am new to this sql server. So any one could you please help me in this aspect.

Thanks in advance

Special character problem



Using a gridView to read some data from a SQL database.

The user can select a record in the gridview.

On the SelectedIndexChanged property I populate this to a couple of text boxes & drop down list ; txtCountry,ddlProvince,ddlCity.

I have special characters in France ( accent marks) and when I populate it to the drop down list it fails giving out the error message

"SelectedValue which is invalid because it does not exist in the list of items".

Example of items that I try to populate are as follows. ( separated by commas)


When I looked in the drop down lists for Province and Cities  I see those Provinces there in the item list.

When I debug line by line the word ÃŽLE-DE-FRANCE comes out like  &#206;LE-DE-FRANCE  which is not there in the drop down list.  Got to know the ÃŽ is typed by pressing down ALT+206 and lloks like this is what is coming in at the start of the string above.

Any suggestions how to overcome this issue?


PS: The drop down lists for Province and Cities are also populated from the same SQL Database which has the above accent characters. The list that is displayed c

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