#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    How do I remove specific numbers from a string?


    I have this string in PHP

    Hopelessly Incredible |SPG:M| 766 STEAM_0:1:20130600 " banned "A Blatantly Obvious Hacker 740 STEAM_0:1:55386073 " (minutes "0") (reason "Multi-Hack")

    The Format of the string is: Name1 Number(0-3 digits) Steam_0:x:xxxx offense (banned/kicked/mute etc) Name2 Number(0-3 digits) Steam_0:x:xxxx time reason

    My goal is to remove the values 766 and 740 because it is just garbage. Those values can have single, double, and triple digits. The next step would be to strip STEAM_0:1:20130600 and STEAM_0:1:55386073 out of the string and capture it in a new variable. The only constant is STEAM_0: the rest can change.

    I am still learning regex but I fear this is a bit complicated for me to do. Some guidance would be most appreciative.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Not 100% sure what the various parts are in that example, but I'd guess
    Code:
    "(.*?) (\d{1,3}) (STEAM_0:\d:\d+) " (\S+) "(.*?) (\d{1,3}) (STEAM_0:\d:\d+) " \(\S+ "\d+"\) \(reason "(.*?)"\)
    .*? is "minimum length of stuff needed for the whole expression to match",
    \d is a digit, {1,3} is 1-3 of them, and + is more than one,
    \S is stuff that isn't whitespace.

IMN logo majestic logo threadwatch logo seochat tools logo