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

    Join Date
    Dec 2016
    Posts
    2
    Rep Power
    0

    regex: value after a regex match between square brackets?


    Hello there i need some help
    Here is my Problem :

    I have this syslog:
    [name]:USB Composite Device [class]:Universal Serial Bus controllers [guid]:36fc9e60-c465-11cf-8056-444553540000 [deviceID]:USB\VID_1C4F&PID_0002\5&2377F6EF&0&2

    How can i exctract this logmessage after the square brackets?

    Example for [class] (class match between square brackets (value after a this regex match between square brackets?)
    Value "Universal Serial Bus controllers"

    Example for [[guid]:
    Value "36fc9e60-c465-11cf-8056-444553540000"

    Many thanks!
    Puemer
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,394
    Rep Power
    9645
    The pattern I would try reads like
    Find '[', a word, ']:', then extract the least amount of text until a space and the next [word], or the end of the string.
    Code:
    \[(\w+)\]:(.*?)(?= \[\w+\]|$)
    Knowing your regex engine and what you've tried so far would be helpful too.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Posts
    2
    Rep Power
    0
    Wow, thanks for the help. It works wonderfully!

    Many thanks!
    Puemer

IMN logo majestic logo threadwatch logo seochat tools logo