Menu

Need help using regex

2008-04-23
2012-11-13
  • TheBladeRoden

    TheBladeRoden - 2008-04-23

    So I have a server log with about 600 lines of

    attacker_position "707 -772 -940"> <victim_position "452 -570 -935">
    attacker_position "707 -806 -940">
    attacker_position "722 -619 -940"> <victim_position "246 -671 -940">
    attacker_position "732 -599 -898">
    attacker_position "732 -599 -898"> <victim_position "549 -538 -940">
    attacker_position "733 -505 -940"> <victim_position "810 -529 -940">
    attacker_position "744 -591 -940"> <victim_position "1038 -383 -940">
    attacker_position "766 -1030 -940">
    attacker_position "766 -1030 -940"> <victim_position "708 -1115 -940">
    attacker_position "766 -1030 -940"> <victim_position "708 -1115 -940">
    attacker_position "775 -334 -916"> <victim_position "441 -578 -935">
    attacker_position "797 -651 -940"> <victim_position "393 -746 -918">
    attacker_position "810 -614 -940"> <victim_position "752 -520 -940">
    attacker_position "821 -502 -940"> <victim_position "325 -573 -935">
    attacker_position "863 -621 -940">
    attacker_position "871 -324 -940"> <victim_position "933 -541 -940">
    attacker_position "871 -324 -940"> <victim_position "933 -541 -940">
    attacker_position "887 -376 -940"> <victim_position "-252 -531 -940">
    attacker_position "907 -493 -940"> <victim_position "1038 -147 -937">
    attacker_position "913 -660 -940"> <victim_position "804 -557 -940">
    attacker_position "922 -773 -940">
    attacker_position "94 995 -299"> <victim_position "87 1145 -394">

    So is there some sort of Regex string that'll return only the lines with attackers and not those with both attackers & victims? This is the furthest I've gotten but it still returns every line.

    attacker_position ".*[^"]">$

    So, any tips?

     
    • Jerry

      Jerry - 2008-05-08

      One of these will find only the lines without victim
      Which to use depends on if there is any whitespace after the >
      No-white space:
      attacker_position ".[0-9]+ .[0-9]+ .[0-9]+">$
      one white space:
      attacker_position ".[0-9]+ .[0-9]+ .[0-9]+">.$
      two white space:
      attacker_position ".[0-9]+ .[0-9]+ .[0-9]+">..$

      Jerry

       
      • Fool4UAnyway

        Fool4UAnyway - 2008-05-08

        Use the following single regex to find or show all the lines you want:

        attacker_position "\d+ \-\d+ \-\d+"> *$

        Of course, you can also use the victim_position (part) to hide or delete lines that you do not want.

         
    • TheBladeRoden

      TheBladeRoden - 2008-04-23

      nevermind I just found the "Hide lines without clipboard text" command

       
    • Fool4UAnyway

      Fool4UAnyway - 2008-04-23

      schijt

       
      • Fool4UAnyway

        Fool4UAnyway - 2008-04-23

        I'm sorry about that. I just wrote a nice reminder, referring to a couple of previous threads and then I simply pushed the Back button. So I lost my message completely. The previous message should read something like "&@#!*".

         
    • Fool4UAnyway

      Fool4UAnyway - 2008-04-23

      Will you allow me to reply still. Perhaps these references may to of use to other readers. These "Need help using regex" threads are tremendously popular, you know.

      You can use the TextFX features to Show or Hide lines (not) containing some text or regular expression copied to the clipboard.

      "How to: copy lines by regex using TextFX Viz" (Help forum)
      http://sourceforge.net/forum/forum.php?thread_id=1964719&forum_id=331754

      The results, however, may not be 100% correct.

      "Bug in TextFX Viz-Hide Lines with Text"
      http://sourceforge.net/forum/forum.php?thread_id=1986375&forum_id=482781

      Here's a thread dealing with only copying the matches themselves, instead of lines containing them.

      "copy to clip all text matching regex pattern" (Help forum)
      http://sourceforge.net/forum/forum.php?thread_id=2012623&forum_id=331754

      This thread also contains a message telling you which tools you can use to do either, extract all matching lines or all matches only, at once.

      "Tools to find and copy regex matches in files" (New)
      http://sourceforge.net/forum/message.php?msg_id=4915704