Web Analytics Made Easy -
StatCounter Regex with anything other than InStr? - CodingForum

Announcement

Collapse
No announcement yet.

Regex with anything other than InStr?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regex with anything other than InStr?

    Look at this pattern...
    openTags.Pattern = "\<([A-za-z0-9]{1,}) {0,1}[^\>.]*\>"

    Finds all open tags... Now you can access the two different bracketed part by $1 and $2 while using the replace function. HOwever, can I use the $1's and $2's in an Instr? In this pattern $1 will contain the tag name eg. "a" or "font" or "h1". I want to search to see if "/" & the tag name e.g. "/a" or "/font" or "/h1" and IF thats the case... do some replace... can that be done?
    I'm gonna find a way to download the internet if its the last thing I do...
    Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished

  • #2
    Of course it can, you could just use a different pattern. It'd be pretty much the same except tweaked to look for closing tags. Because from what I can tell by looking at that one, it won't find closing tags so I'm not sure what you ment by using instr.
    OracleGuy

    Comment


    • #3
      openTags.Pattern = "\<([A-za-z0-9]{1,}) {0,1}[^\>.]*\>"

      $1 would hold the name of the tag... so I could search for "</" + $1 + ">" to find the closed form of the tag. Thats what I was thinking that I could use inStr for. However... I vaguely recall that you can look for some repeated patterns somehow in regexp's but I just don't know how to.... could you help me out?
      I'm gonna find a way to download the internet if its the last thing I do...
      Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished

      Comment


      • #4
        This is vb code, but it should translate pretty well over to ASP. Basically it gets all the matches from your test data which I assume would be a hunk of HTML. So then code would go through each match and grab $1 and throw it in that value. So basically if you needed to do an instr, you have what you need.

        Code:
        Set Matches = regEx.Execute(TestData)
        For Each Match In Matches
            'Your equivalent to $1
            DollarSign1 = Match.Submatches(0)
            'Do whatever other operations you want to do or stash that variable for later
        Next
        However there may be a better solution.
        You can use regex.replace()
        with this <([a-zA-Z]+).+?>(.|\n)+?<\1>
        Code:
        regex.global = true
        regex.IgnoreCase= true
        regex.pattern = <([a-zA-Z]+).+?>(.|\n)+?<\1>
        newhunkoftext = regex.replace(oldhunkoftext, "Replacement text $1")
        And assuming my VB isn't all rusty that would replace each tag on the page with Replacement Text *Tag*. The regex may need a little finesse as well, just cooked it up right now.
        Whats the point of a signature?

        Comment


        • #5
          Originally posted by CrzySdrs
          Code:
          ..
              DollarSign1 = Match.Submatches(0)
          ..
          Man, thats the answer to ALL my questions. All I really wanted to do was to access the submatches and get it stored somewhere... thanks man!
          I'm gonna find a way to download the internet if its the last thing I do...
          Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished

          Comment


          • #6
            it can be done in several ways

            Comment

            Working...
            X