locked
Extract a sub-string from string with Regular expression RRS feed

  • Question

  • Hi all,

    I need to extract from this string,

    "2011-10-20 16:16:40 26.104.99.49(via 26.104.99.49) TRAP, SNMP v1, community public  cmgTrapTypes Enterprise Specific Trap (30) Uptime: 154 days, 23:18:56.27  cmgTrapSubsystem.2 = STRING: "HW" cmgTrapOnBoard.2 = STRING: "no" cmgTrapLocation.2 = STRING: "050V2" cmgHardwareFaultMask.2 = Hex-STRING: 00 00 80  cmgPrimaryClockSource.2 = STRING: "v2" cmgSecondaryClockSource.2 = "" cmgActiveClockSource.2 = INTEGER: primary(1) "

    two sub-string which are:

    (30) and 050V2

    anybodies can help me to estract theese value with regular expression?

    thanks a lot

    Leonardo

    Friday, October 21, 2011 9:21 AM

Answers

  • Well you could use something like this:

    \(\d{2,}\)|STRING\:\s\"\d{3}[A-Z]\d\"

    or

    \(\d{2,}\)|(?<=STRING\:\s\")\d{3}[A-Z]\d


    John Grove, MCC - Senior Software Engineer
    • Edited by JohnGrove Friday, October 21, 2011 2:44 PM
    • Proposed as answer by Paul Zhou Tuesday, October 25, 2011 7:23 AM
    • Marked as answer by Paul Zhou Monday, October 31, 2011 6:03 AM
    Friday, October 21, 2011 2:42 PM

All replies

  • Well you could use something like this:

    \(\d{2,}\)|STRING\:\s\"\d{3}[A-Z]\d\"

    or

    \(\d{2,}\)|(?<=STRING\:\s\")\d{3}[A-Z]\d


    John Grove, MCC - Senior Software Engineer
    • Edited by JohnGrove Friday, October 21, 2011 2:44 PM
    • Proposed as answer by Paul Zhou Tuesday, October 25, 2011 7:23 AM
    • Marked as answer by Paul Zhou Monday, October 31, 2011 6:03 AM
    Friday, October 21, 2011 2:42 PM
  • Well you could use something like this:

    \(\d{2,}\)|STRING\:\s\"\d{3}[A-Z]\d\"

    or

    \(\d{2,}\)|(?<=STRING\:\s\")\d{3}[A-Z]\d


    John Grove, MCC - Senior Software Engineer

    Thanks a lot!
    Tuesday, October 25, 2011 7:30 AM