Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Need helping stripping certain bits of data out of a string

    I have a string which will be in the format
    SQLSTATE[XXXXX]: Column not found: 1054 Unknown column 'XXXXX' in 'field list'
    where the only bits of changing data will the the XXXXX's. I need to get this data so I can compare it and echo out certain messages. I think i'll need to use some regex command but I can't seem to figure out what it should be.

    Can anyone give me a hand writing the regex?

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    this site is good for that kind of thing

    http://txt2re.com


    PHP Code:

    <?php
      
    # URL that generated this code:
      # http://txt2re.com/index-php.php3?s=SQLSTATE[XXXXX]:%20Column%20not%20found:%201054%20Unknown%20column%20%27XXXXX%27%20in%20%27field%20list%27&16&17

      
    $txt='SQLSTATE[XXXXX]: Column not found: 1054 Unknown column \'XXXXX\' in \'field list\'';

      
    $re1='.*?';    # Non-greedy match on filler
      
    $re2='(?:[a-z][a-z0-9_]*)';    # Uninteresting: var
      
    $re3='.*?';    # Non-greedy match on filler
      
    $re4='((?:[a-z][a-z0-9_]*))';    # Variable Name 1
      
    $re5='.*?';    # Non-greedy match on filler
      
    $re6='(?:[a-z][a-z0-9_]*)';    # Uninteresting: var
      
    $re7='.*?';    # Non-greedy match on filler
      
    $re8='(?:[a-z][a-z0-9_]*)';    # Uninteresting: var
      
    $re9='.*?';    # Non-greedy match on filler
      
    $re10='(?:[a-z][a-z0-9_]*)';    # Uninteresting: var
      
    $re11='.*?';    # Non-greedy match on filler
      
    $re12='(?:[a-z][a-z0-9_]*)';    # Uninteresting: var
      
    $re13='.*?';    # Non-greedy match on filler
      
    $re14='(?:[a-z][a-z0-9_]*)';    # Uninteresting: var
      
    $re15='.*?';    # Non-greedy match on filler
      
    $re16='((?:[a-z][a-z0-9_]*))';    # Variable Name 2

      
    if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7.$re8.$re9.$re10.$re11.$re12.$re13.$re14.$re15.$re16."/is"$txt$matches))
      {
          
    $var1=$matches[1][0];
          
    $var2=$matches[2][0];
          print 
    "($var1) ($var2) \n";
      }

      
    #-----
      # Paste the code into a new php file. Then in Unix:
      # $ php x.php 
      #-----
    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    tomharto (03-20-2013)

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Thanks, that sites really useful .

    Using a mix of that, your answer and google I came up with what seems to be working.

    PHP Code:
    $re1='.*?';    # Non-greedy match on filler
      
    $re2='\[(.*?)\]';    # Square Braces 1
      
    $re3='.*?';    # Non-greedy match on filler
      
    $re4='(\'[a-z]+\')';    # Single Quote String 1

      
    if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4."/is"$msg$matches))
      {
          
    $word1=$matches[1][0];
          
    $word2=$matches[2][0];
          print 
    "($word1) ($word2) \n";
      } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •