ereg and me again ;)

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

    #1

    ereg and me again ;)

    Hello all,

    last time, ereg specialists did help me, so I ask again:

    base pattern: some texte her [a number between 1 and 100]
    result: the number alone

    So ? any idea ?

    Aphrael ;-)
    --
    "La demande mondiale d’ordinateurs n’excédera pas cinq machines."
    (Thomas Watson, Fondateur d'IBM, 1945)
  • Michael Fesser

    #2
    Re: ereg and me again ;)

    .oO(Aphrael)
    [color=blue]
    >last time, ereg specialists did help me, so I ask again:
    >
    >base pattern: some texte her [a number between 1 and 100]
    >result: the number alone
    >
    >So ? any idea ?[/color]

    Assuming that I understood correctly - try if the following patterns
    work for you:

    for ereg():
    '\[([0-9]+)]'

    for preg_match() (preferred, more flexible and faster in most cases):
    '#\[(\d+)]#'

    If that's not enough post some more examples and the expected results.

    HTH
    Micha

    Comment

    • John Dunlop

      #3
      Re: ereg and me again ;)

      Aphrael wrote:
      [color=blue]
      > last time, ereg specialists did help me, so I ask again:[/color]

      Must it be ereg? Preg_* functions are better because they
      support PCREs.
      [color=blue]
      > base pattern: some texte her [a number between 1 and 100]
      > result: the number alone[/color]

      Between one and a hundred inclusive:

      `.*?\[([1-9]\d?|100)\]`s

      Anything is matched until a left square bracket. After
      that, either a digit between one and nine followed by an
      optional digit between zero and nine, or the number one
      hundred, is captured. Then a right square bracket is
      matched. The s pattern modifier makes the dot metacharacter
      match newlines.

      HAGS!

      --
      Jock

      Comment

      • Victor Rades

        #4
        Re: ereg and me again ;)

        try this ereg: ([0-9]{1,2}|100)

        -- BEGIN OF CODE - CUT HERE --
        $delimiter = "\s";
        preg_match("/$delimiter([0-9]{1,2}|100)$deli miter/", $your_text, $number);
        echo "<pre>\n" . print_r($number , true) . "</pre>";
        -- END OF CODE -- CUT HERE --


        Aphrael <aphrael@isuiss e.com> wrote in message news:<414b6b97$ 1_1@news.bluewi n.ch>...[color=blue]
        > Hello all,
        >
        > last time, ereg specialists did help me, so I ask again:
        >
        > base pattern: some texte her [a number between 1 and 100]
        > result: the number alone
        >
        > So ? any idea ?
        >
        > Aphrael ;-)[/color]

        Comment

        Working...