Re: getting off ground with reg exp's

From: Nobody (nobody_at_project-sca.org)
Date: 10/01/04

  • Next message: Dicki Smits: "why do this not create a database?"
    Date: Fri, 01 Oct 2004 22:40:38 +0200
    
    

    D. Alvarado schrieb:
    > Hello,
    > I have a string, that will be in the form
    >
    > varchar(###)
    >
    > where "###" are numeric digits. There could be between 1 and 3 of
    > these digits. I am trying to write a regular expression to get the
    > value of "###". However, this expression is faulty
    >
    > $str = "varchar(255)";
    > $maxlen = -1;
    > $matchArr = array();
    > if
    > (preg_match('/varchar\((\d+)\)/i', $str, $matchArr)) {
    > $maxlen =
    > $matchArr[0];
    > }
    >
    > Can anyone suggest an expression that will work? The value of $maxlen
    > is always equal to $str!
    >
    > Thanks, - Dave

    $maxlen = preg_replace('/(varchar\()(\d{1,3})(\))/', '$2', $str);

    -- 
    -------------------------------------------------------
    Try this: SCA the Smart Class Archive for PHP
    http://www.project-sca.org
    -------------------------------------------------------
    

  • Next message: Dicki Smits: "why do this not create a database?"
  • Quantcast