Regex issue


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Regex issue

  1. #1
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174

    Regex issue

    Hey,

    I have a string similair to this inputted: a[1-3]b[2]c
    I want to split it into [1-3] and [2].
    My current code is: Regex.Split(txtPwFormat.Text, "[\[0-9-\]]+")

    It works like a charm in determining which pieces i don't want, and will output an array containing a, b and c.

    So is there another method, one that is similar to preg_match_all in php, in vb.net? Or do I have to restructure my format?

    Cheers
    BN

  2. #2
    Join Date
    Jul 2007
    Posts
    139
    I always use a deliminator, a comma for instance. e.g. a,b,c,d


    steve

  3. #3
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174
    Hey,

    I dno not see how I could work with simple delimeteres here. I need to be able to split a[1-3]b[2]c like described in the first post

    Cheers
    BN

  4. #4
    Join Date
    Jul 2007
    Posts
    139
    I'm not sure about your string structure, I don't understand the a ,b & c.

    The way I understand it you want extract the vaues in brackets, if this is the case your initial string needs the format

    [1-3],[2]

    you can accomplish this by using

    split(my_text_string,",")

    If this isn't what you need try and be more precise about the input and output strings you require, exactly what do you want the values of your output array to be?


    Steve
    Last edited by Steve36445; 02-07-2009 at 08:37 AM.

  5. #5
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174
    Hey,

    The inputted string by the user, which can look like a[1-3]b[2]c, or spamz[4]blaat[1-2]omg does contain information i need in my program. I need both the text parts, and the number parts between brackets.

    Cheers
    BN

  6. #6
    Join Date
    Jul 2007
    Posts
    139
    Please give an example of exactly what output you requie
    Is it for instance you need two string arrays eg.


    a(0)="a"
    a(1)="b"
    a(2)="c"

    and

    b(0)= "[1-3]"
    b(1)="[2]"



    Steve
    Last edited by Steve36445; 02-07-2009 at 09:02 AM.

  7. #7
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174
    Hey,

    That is indeed the output I want. (assuming you forgot to increase the index nrs of the first array.)

    I'm trieng to make an adaptation of this php script (see attachment).
    Attached Files Attached Files

  8. #8
    Join Date
    Jul 2007
    Posts
    139
    How big is the string to split? Are we talking kb,mb or what?

    Can the input string be changed to be deliminated? It can be done without but it is easier if it is delimiated in the first place

    steve

  9. #9
    Join Date
    Jul 2007
    Posts
    139
    Try this, add two listboxes to the form, leave the names as default-

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim input_string = "a[1-3]b[2]c"
            Dim text_array(10) As String
            Dim bracket_array(10) As String
            Dim split_array() As String
            Dim text_array_counter As Int16
            Dim bracket_array_counter As Int16
            '       First delininate the string
            input_string = Replace(input_string, "[", ",[")
            input_string = Replace(input_string, "]", "],")
    
            MessageBox.Show("Deliminated string " + input_string)
            'split into one array
            split_array = Split(input_string, ",")
            'put in their own array
            For Each item As String In split_array
                If InStr(item, "[") Then
                    bracket_array(bracket_array_counter) = item
                    bracket_array_counter = bracket_array_counter + 1
                    ListBox1.Items.Add(item) ' display the reults
                Else
                    text_array(text_array_counter) = item
                    text_array_counter = text_array_counter + 1
                    ListBox2.Items.Add(item) ' display the reults
    
                End If
    
            Next
        End Sub
    End Class
    Last edited by Steve36445; 02-07-2009 at 10:18 AM.

  10. #10
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174
    Hey,

    Your code is working, thnx alot for it!

    It is not an option to let the input be delimetered, casue the user has to enter it, and they will have a hard time understanding how to brackets work by itself

    Cheers
    BN

Similar Threads

  1. Excel OLEDB Create Table Issue
    By gsmmc in forum Database
    Replies: 17
    Last Post: 10-02-2008, 01:48 PM
  2. C# RegEx Mess
    By SDSoftDev in forum .NET
    Replies: 1
    Last Post: 07-17-2008, 08:16 AM
  3. movenext & moveprevious issue
    By dman in forum VB Classic
    Replies: 13
    Last Post: 02-22-2008, 12:36 PM
  4. Column select with RegEx
    By Tony Lintunen in forum .NET
    Replies: 1
    Last Post: 02-04-2006, 05:20 PM
  5. Replies: 0
    Last Post: 09-19-2001, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center