Results 1 to 8 of 8

Thread: [Resolved] RegEx Help

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] RegEx Help

    I've never worked with Regular Expressions in VB, but am pretty good with it in PHP.

    What I need to do is get rid of <font>text here</font>, no matter what "text here" is.

    In VB, the expression would be something like "/<font>(.*)</font>/", but that doesn't seem to work in VB.

    Also, when I distribute this application, what files will I have to include for the Reg Expression Library?
    Last edited by The Hobo; Jul 23rd, 2003 at 03:45 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    This is what I'm trying:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmdConvert_Click()
    4. Dim strHTML As String
    5. Dim regEx As RegExp
    6.  
    7.   Set regEx = New RegExp
    8.   regEx.IgnoreCase = True
    9.   regEx.Global = True
    10.  
    11.   strHTML = txtHTML.Text
    12.   strHTML = Replace(strHTML, "<html>", "", , , vbTextCompare)
    13.   strHTML = Replace(strHTML, "</html>", "", , , vbTextCompare)
    14.  
    15.   regEx.Pattern = "<font>(.*)</font>"
    16.  
    17.   strHTML = regEx.Replace(strHTML, " this was replaced ")
    18.  
    19.   rtfDisplay.Text = strHTML
    20.  
    21.   Set regEx = Nothing
    22. End Sub

    And it seems to replace all instances, but it only shows " this was replaced " once, instead of for all occurances?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Anybody?

    I really just need to know how to access the wildcards. In PHP, "\\1" would access the value of the first wildcard in the replacement, but that doesn't work here.

    I've searched the forums and the web, but haven't found anything.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    can you use RegEx in vb6 then? cuz i've used it in vb.net / C# / javascript , but i've never heard of it being used in vb6 and i cant seem to find a way to reference it. if you are trying to convert a html file to a text file ( minus the html ) you can use Doument.documentelement.InnerText
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Yes, you can use it in VB6. No, I am not trying to do that.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    To use it in VB6, you must include a reference to Microsoft VBScript Regular Expressions 5.5 (or 1.0).

    Then use code similar to what I have posted above.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    You are missing one small thing (?) mark.
    Code:
    regEx.Pattern = "<font>.*?</font>"

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks. I ended up just doing a series of replaces, but I'll probably try to hook up the expressions again later, if I continue the project.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width