regex , ereg() Problems???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dkirkdrei@yahoo.com

    #1

    regex , ereg() Problems???

    I am having a problem verifying characters in a variable, I am trying
    to create a conditional statement based on whether or not the first two
    characters of a variable contain "E9". The variable will always be
    either a 6 or a 7 digit, alpha-numeric string begining with "E". I have
    tried the following ereg() statement and it picks up everything because
    it begins with "E". I cannot seem to find any examples for matching
    characters in a specific location within a string except for the
    begining or the end. I am sure there is a simple solution. Any ideas??

    (ereg("^[E9]", $enumber))

  • Rik

    #2
    Re: regex , ereg() Problems???

    dkirkdrei@yahoo .com wrote:
    I am having a problem verifying characters in a variable, I am trying
    to create a conditional statement based on whether or not the first
    two characters of a variable contain "E9". The variable will always be
    either a 6 or a 7 digit, alpha-numeric string begining with "E". I
    have tried the following ereg() statement and it picks up everything
    because it begins with "E". I cannot seem to find any examples for
    matching characters in a specific location within a string except for
    the begining or the end. I am sure there is a simple solution. Any
    ideas??
    >
    (ereg("^[E9]", $enumber))
    This would mean: Match if the first character if it's in the block between
    [], i.e. everything starting with 'E' _or_ '9' will match.
    Do not use [] if you're looking for an exact string.

    Starting with E9:
    preg_match('/^E9/',$number);

    Case insensitive (either E or e):
    preg_match('/^E9/i',$number);
    --
    Rik Wasmus


    Comment

    • dkirkdrei@yahoo.com

      #3
      Re: regex , ereg() Problems???


      Rik wrote:
      dkirkdrei@yahoo .com wrote:
      I am having a problem verifying characters in a variable, I am trying
      to create a conditional statement based on whether or not the first
      two characters of a variable contain "E9". The variable will always be
      either a 6 or a 7 digit, alpha-numeric string begining with "E". I
      have tried the following ereg() statement and it picks up everything
      because it begins with "E". I cannot seem to find any examples for
      matching characters in a specific location within a string except for
      the begining or the end. I am sure there is a simple solution. Any
      ideas??

      (ereg("^[E9]", $enumber))
      >
      This would mean: Match if the first character if it's in the block between
      [], i.e. everything starting with 'E' _or_ '9' will match.
      Do not use [] if you're looking for an exact string.
      >
      Starting with E9:
      preg_match('/^E9/',$number);
      >
      Case insensitive (either E or e):
      preg_match('/^E9/i',$number);
      --
      Rik Wasmus
      Thanks Rik, I had tried preg_match() but I was trying to use the square
      brackets and it was not working. I will give your suggestions a try.
      Thanks again for the response...

      Comment

      Working...