Results 1 to 4 of 4

Thread: Bit of regex

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Bit of regex

    This is my second post in this thread... The first one I made I got accused of writing a hack. Id just like to start off saying that this is no such thing. If you would look at my code instead of just assuming you could see that.

    Anyhoo. This is a small sub routine for my bot. The deal is when a player dies in the game a bounty number is displayed at the end of there name. The bounty number is always between brackets "(402)" And can be anywhere from (0) to (30000).

    Now the issue is that i need to remove this number from there name so the bot can reply to them. Here is the code I came up with using regex.

    Killed(0) is the person who got the kill
    m is match. (each match in string)
    Then item_index route is adding the name to a list for further processing.

    Code:
     t = killed(0)
          re.Pattern = "\(*\d\d*\)$"
          re.Global = True
          For Each m In re.Execute(t)
          killed2 = Split(killed(0), m.Value)
          item_index = SendMessage2(List1.hwnd, LB_FINDSTRING, -1, killed2(0))
             Next
    What I was thinking could be done is some reverse parsing. Since the bounty is displayed at the end of a name and is always encapsulated in ()'s if there was some way to find the first ( from right to left in a string that would work

    Ah and on a side note the players name May or may not contain brackets.
    Last edited by Alvanian; Dec 10th, 2007 at 05:24 PM.

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: Bit of regex

    I think this will do what you want

    Code:
    Private Function ParseName(ByVal s As String)
         Return s.Substring(0, s.LastIndexOf("("))
    End Function

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Bit of regex

    Hum I see what your trying to do and I think it would work. Although I dont think that is the correct code for Visual basic. Maby its VB.net though then again I wouldn't know as Ive never used it.

  4. #4
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: Bit of regex

    sorry about that, I assumed .net. I haven't used vb6 in a long time but it will be something like this:

    vb Code:
    1. Mid$(s, 1, InStrRev(s, "("))

    I don't think that's completely right, but I don't have vs6 installed to test right now.

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