.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

Split string using Regex with escape sequences

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
What is the regex to split a string using the delimiter ';', but not split on '\;' ? Backslash would be my escape character in my split string, so finding '\;' would not split, but '\\;' would split. For example I want a regex that would split the following:     "aaa;bb;cccc\;dd\;eee\\;ff\\;ggg\\\;hhh" into the following string array:     aaa     bb     ccc\;dd\;eee\\     ff\\     ggg\\\;hhh   Thanks!   -Sylvain

View Complete Post

More Related Resource Links

string.Split - not all characters allowed as separator



I am working on a site where I use the Split function on a string.

To make sure I used a separator character that I do not use anywhere in the data I selected the character '£'.

This worked fine in Firefox and Safari, but in IE8 I get an 'Index out of range' error, so apparently the '£' character is not handled correctly.

I changed the separator to ';', and then it works fine.



How to split string?


I have a string that looks like this: pic1*pic2*pic3*

I want to take out every pic from the string like this:


I got the first pic but how do i get the other two?

Dim line as string = "pic1*pic2*pic3*"
Dim pic1 As String
Dim pic2 As String
Dim pic3 As String

pic1 = line.Substring(0, line.IndexOf("*"))
pic2 = ?
pic3 = ?

RegEx Request - Extract an tag from string...

Hello, Can anyone give me a regular expression that will extract the <img> tag from a string.  I am receiving descriptions from an rss feed and the description contains an <img> tag in the text.  I want to extract the <img> so that I can display it in a different location on my page. I have fooled with some regular expressions, but my knowledge of them is not very good. Thanks in advance for any help!!

regex split implementation

hi I have created a function to implement the regex.split in sql. Here's my code: private static IEnumerable<IndexedValue<T>> ToIndexedValue<T>(IEnumerable<T> list) { int idx = 1; foreach (T value in list) yield return new IndexedValue<T>(++idx, value); } private struct IndexedValue<T> { public int Index; public T Value; public IndexedValue(int index, T value) { Index = index; Value = value; } } [SqlFunction(FillRowMethodName = "FillSplit", TableDefinition = "[ID] int, [Value] nvarchar(max)")] public static IEnumerable RegexSplit(SqlString input, SqlString pattern) { if (input.IsNull) input = String.Empty; if (pattern.IsNull) pattern = String.Empty; try { return ToIndexedValue<string>(Regex.Split(input.Value, pattern.Value, Options)); } catch { throw; } } public static void FillSplit(object obj, out int id, out SqlString value) { IndexedValue<string> iv = (IndexedValue<string>)obj; id = iv.Index; value = iv.Value; } However when i try it i get id values but empty text values. Can someone help?

How to split the string value ?

 Hi I  have a string value ie) = '1001010' I want to split one word by one word. like  as 1 0 0 1 0 please guide me.  

Extract String using RegEx

HelloI have below data in string format in a field in table and would like to parse the name from the quantity. The name should be anything before it hits a numeric numberin below example CHLORPHENIRAMINE is the name. i really appreciate if i can get a regex to extract the name from below string                                    "CHLORPHENIRAMINE 8MG CAP SA",                                    "CHLORPHENIRAMINE 12MG CP SA",                                     "CHLORPHENIRAMINE 4MG TABLET",                                     "CLEMASTINE FUM 2.68MG TAB",             &n

Split a String from a listbox to enter data in a table


Currently, I have a listbox that the selected items are inserted into the database by a string. Now I need to add a new feature that the searches are suppose to be postback individually so the selected values from the listbox need to be inserted into the database individually so the search can work. Is it possible to split an string into separate variables or into an array?

Thanks for your help,



Following is my store procedure and my back code:

<script runat="server">
    Protected Sub insertcompanydata_click1(ByVal sender As Object, ByVal e As EventArgs)

        Dim tobresults2 As String        
        Dim li As ListItem
        Dim myArrayList As ArrayList = New ArrayList()
        Dim strarr() As String
        For Each li In txttoblb.Items
            If li.Selected = True Then
            End If

        strarr = myArrayList.ToArray(Type.GetType("System.String"))
        tobresults2 = String.Join(",  ", strarr)

        Dim txtloblb1 As String
        Dim lin As ListItem
        Dim myArrayList1 As ArrayList = New ArrayList()
        Dim strarr1() As String

unrecognized escape sequence in SQL connection string



In my program, I want to make database connectivity, but when i write a connection string, complier says that it is unrecognized escape sequence(which is bolded in the following string), the string is :

Data Source=HIMANSHU\SQLEXPRESS;Initial Catalog=Himanshu;Integrated Security=True

How can I resolve my problem?


Replace space from string - REGEX.



I have some problem with RegEx.

I have text:

"something here [tagQuote=Name of Author]bla bla bla[/tagQuote] something here"

And now I want to replace all the whitespace character in quote attribute with "%#%#%#%".

So I want to have: [tagQuote=Name%#%#%#%of%#%#%#%Author]bla bla bla[/tagQuote]

So remove all of the whitespaces between "[tagQuote=" and "]...[/tagQuote]"

Regex solution to ID Excel Cell references in an Excel Formula string


Is there a RegEex solution to accomplish the following:

- Assuming Operator Pattern is "[/*^&()=<>,+-]"
- Cell References are pre-fixed Post-fixed by an Operator (including a comma)
- Cell References Start with Alpha Characters without-interruption - by an operator
    then Followed by numerics-without-interruption - by an operator

----------------------FORMULA STRING INPUT----------------| |---OUTPUT---|
                                                                                        Cell    Cell
1) =I82*I83/365*0.11      <  <  <  <  <  <  <  <  <  <  <  < >  I82     I83
2) =IF(H84>H80*0.91,H84,0.91*H80) <  <  <  <  <  <  <  < >&nbs

Split string


hi all

i want to spilt 115:USD:LKR this string from oracle script. return value should be 115.

pls provide me sql script


RegEx: converting email address to mailto link in a string using VB



i have tried various ways to accomplish this, but to no avail.  I don't know how to generate the replacement text (mailto link) so I just used a bunch of x's until I can figure it out.  Here is what I have (which currently not replacing emails in string):

Here is my Code behind:

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load


            Me.lblText.Text = DAL.PortLog.PortLogs.PortLogToHTML(Me.TransitID)
        End Sub

Here is the called function to replace email addresses:

    Public Shared Function ConvertEmailToMailToLinks(ByVal textToConvert As String) As String

        Dim pattern As String = "\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"
        Dim input As String = textToconvert
        Dim replacement As String = "xxxxxxxxxXXXXxxxxx"  'test
        Dim rgx As New Regex(pattern)
        Dim result As String = rgx.Replace(input, replacement)

        Return result

    End Function

Here is the DAL code:

Split string after word


Hi everybody,

How can I split a string from some word.

string test = "Hellow world one two three";

I would lile to get the string part after the word world?? The result will be after splitting the string: "one two three"

split string sql server 2005



I have a table called SubjectRank that provides subject and it's ranking.

I have a string that can be in any format. It can be 'hello cat, how -are you lion?' or 'yes horse'. In short it can be received in any manner and i have no control on how user sends the string.

What I need to do is check if the string contains any words in the subject column. If yes I need to return that word.

In addition if the string contains more than one subject from the table than I must check the ranking and return the value with the highest ranking. (1 lowest) So if the string contains 'hello cat, how -are you lion?' the sp must return the word lion.


How can I achieve this?




String.Split with with tab as separator


I should read the substrings of this file:

1	1	-1738.20118241	6787.03549108	
2	2	-1803.20118241	6759.73549108	
3	3	-2193.20118241	6759.73549108	

I haved used the tab control "\t" as the separator (there is a tab character between the columns):

      Dim separator() As String = {"\t"}
      Console.WriteLine("separator(0) = {0}", separator(0))
        ' Open the file to read from.
        Using sr As StreamReader = File.OpenText(nomeFile)
          Do While sr.Peek() >= 0
            'Dim line As New StringBuilder
            Dim stringline As String
            Dim stringarray As String()
            Dim x, y, canale 

Split String on underscore



I have a long string and i want to split it on the bases of case change and underscore. here is the following pattern that split on the case change but i also want to split it on the underscore. Can somebody help me out.

private static final String DIVIDER_PATTERN =  "(?<=[^\\p{Upper}])(?=\\p{Upper})"  + "|(?<=[\\p{Lower}])(?=\\d)";

 this pattern split "MyFamilyNameIsFar" to "My Family Name Is Far" but i also want to split if there is underscore. like

"MyFamily_NameIs_Far" to  "My Family Name Is Far"

Can somebody tell me which modification i need in this pattern to handle these kind of situation.


your help would be appreciated.


With Best Regards

Replace Escape char in string


Hello all,

I have a following string

"<Grid><IO/>\n<Body>\n<B>\n<I id=\"AR1\" Def=\"R\" Panel=\"\" Id=\"1\" Name=\"Activity 1\" Prent=\"\" ResourceName=\"Emp 1\" S=\"11/26/2010 12:00:00 AM\" E=\"12/16/2010 12:00:00 AM\" Predecessor=\"0\"/></B>\n</Body>\n</Grid>"

And i want it in following form



      <I id="AR1" Def="R" Panel="" Id="1" Name="Activity 1" Prent="" ResourceName="Emp 1" S="11/26/2010 12:00:00 AM" E="12/16/2010 12:00:00 AM" Predecessor="0"/>     





It means i want to replace \ char from upper string. How can i do this. please help.

I am struck very badly. Thanks in advance. 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