preg_match frustration

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GazK

    preg_match frustration

    Can someone help a regex noob?

    my code:

    $text = "clapham junction 1989";
    $regexp = "[0-9][0-9]{3}";
    $dummy = preg_match($reg exp, $text, $matches);
    echo $matches[0];

    produces the error:

    Warning: preg_match() [function.preg-match]: Unknown modifier '[' in
    blah blah blah

    Have I got the regex wrong? I'm trying to return any 4 digit number in
    $text.

    thanks in advance

    Garry
  • Michael Fesser

    #2
    Re: preg_match frustration

    ..oO(GazK)
    >Can someone help a regex noob?
    >
    >my code:
    >
    >$text = "clapham junction 1989";
    >$regexp = "[0-9][0-9]{3}";
    >$dummy = preg_match($reg exp, $text, $matches);
    >echo $matches[0];
    >
    >produces the error:
    >
    >Warning: preg_match() [function.preg-match]: Unknown modifier '[' in
    >blah blah blah
    You have to use delimiters around your regex, e.g.

    $regexp = '/[0-9][0-9]{3}/';

    See the manual for syntax details.
    >Have I got the regex wrong? I'm trying to return any 4 digit number in
    >$text.
    Shorter:

    /\d{4}/

    Micha

    Comment

    • GazK

      #3
      Re: preg_match frustration

      Michael Fesser wrote:
      .oO(GazK)
      >
      >Can someone help a regex noob?
      >>
      >my code:
      >>
      >$text = "clapham junction 1989";
      >$regexp = "[0-9][0-9]{3}";
      >$dummy = preg_match($reg exp, $text, $matches);
      >echo $matches[0];
      >>
      >produces the error:
      >>
      >Warning: preg_match() [function.preg-match]: Unknown modifier '[' in
      >blah blah blah
      >
      You have to use delimiters around your regex, e.g.
      >
      $regexp = '/[0-9][0-9]{3}/';
      >
      See the manual for syntax details.
      >
      >Have I got the regex wrong? I'm trying to return any 4 digit number in
      >$text.
      >
      Shorter:
      >
      /\d{4}/
      >
      Micha
      That's great Micha, thanks very much.

      Comment

      • Michael Fesser

        #4
        Re: preg_match frustration

        ..oO(GazK)
        >That's great Micha, thanks very much.
        You're welcome.

        Micha

        Comment

        Working...