pattern matching in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jjeanj1
    New Member
    • May 2007
    • 18

    pattern matching in php

    hi, everyone

    I have the following line in a file

    TWS - Maestro Infrastructure, METINTSV50601#T WSFIXCLUOFF.TWS _CLU_OFF:1011,M GR:some (name) Kathryn,AD:some name

    i am using php to some part of the file for example
    server name:METINTSV50 601
    jobname:TWSFIXC LUOFF
    schedulename:TW S_CLU_OFF
    abend#:1011

    Does anyone know a routine to get these string from the line in PHP thank you.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Jean.
    Originally posted by jjeanj1
    TWS - Maestro Infrastructure, METINTSV50601#T WSFIXCLUOFF.TWS _CLU_OFF:1011,M GR:Sbarbaro (Pinto) Kathryn,AD:Trov ello Andrea

    i am using php to some part of the file for example
    server name:METINTSV50 601
    jobname:TWSFIXC LUOFF
    schedulename:TW S_CLU_OFF
    abend#:1011
    So there's a bunch of characters that we don't care about,
    followed by a comma,
    followed by a bunch of characters that we do care about (server name),
    followed by a pound,
    followed by some more characters that we care about (jobname),
    followed by a period,
    followed by some more characters that we care about (schedulename),
    followed by a colon,
    followed by some numbers that we care about (abend#),
    terminated by a comma.

    We can use a regular expression to describe this string:
    [code=php]
    $matches = array();
    preg_match('/,(.+?)#(.+?)\\. (.+?):(\\d+?),/', $string, $matches);

    print_r($matche s);
    [/code]

    That should get you started. For more info on regular expressions, check out this article.

    Comment

    • jjeanj1
      New Member
      • May 2007
      • 18

      #3
      hi i tried what you have on there and it does not work. I am not really sure why.

      i get Array()

      Comment

      • jjeanj1
        New Member
        • May 2007
        • 18

        #4
        Sorry about that pbmods. Everything works great thank you so much for your help. I LOVE THIS SITE!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Jean.

          Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

          Comment

          Working...