Another regex question

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

    Another regex question

    Hello,


    I'm trying to regex an expression like this:

    var1: val11 val12 ... val1N var2: val21 val22 ... val2M ... varI: valI1 ... valIJ

    to get a something like this:

    var1: val11 val12 ... val1N
    var2: val21 val22 ... val2M
    ..
    ..
    ..
    varI: valI1 ... valIJ

    for example a multiple array.

    Any ideas...? Thanks,

    Sebastián Araya
  • Erik Andersson

    #2
    Re: Another regex question

    We need a more detailed example than that in order to be able to help you. I
    can't see any pattern in the examples you gave us so it's very likely that
    the expression we would develope would be wrong.

    Either way.. this might be what you're looking for:

    <?php
    $string = "var1: val11 val12 ... val1N var2: val21 val22 ... val2M ... varI:
    valI1 ... valIJ";
    $new_string = ereg_replace(" ([a-zA-Z0-9]+)\:", "\n\\1:", $string);
    echo $new_string;
    ?>

    --
    Erik Andersson ( E.N.E IT - Australia )
    ENEIT, ENE IT, Informática, soluciones integrales, redes, telefonía, barcelona

    - Australian, high quality web hosting from AU$4.95, all features included.

    "Sebastian Araya" <araya.s@numisy s.com.ar> wrote in message
    news:678aed25.0 312271404.30d8f 5f6@posting.goo gle.com...[color=blue]
    > Hello,
    >
    >
    > I'm trying to regex an expression like this:
    >
    > var1: val11 val12 ... val1N var2: val21 val22 ... val2M ... varI: valI1[/color]
    .... valIJ[color=blue]
    >
    > to get a something like this:
    >
    > var1: val11 val12 ... val1N
    > var2: val21 val22 ... val2M
    > .
    > .
    > .
    > varI: valI1 ... valIJ
    >
    > for example a multiple array.
    >
    > Any ideas...? Thanks,
    >
    > Sebastián Araya[/color]


    Comment

    • Sebastian Araya

      #3
      Re: Another regex question

      Thank you!

      Although I can't explain myself, your solution is brilliant.

      Thanks and Happy New Year!

      Sebastián Araya


      "Erik Andersson" <erik@wcttour.c om> wrote in message news:<3fee23f8$ 0$904$61c65585@ uq-127creek-reader-02.brisbane.pip enetworks.com.a u>...[color=blue]
      > We need a more detailed example than that in order to be able to help you. I
      > can't see any pattern in the examples you gave us so it's very likely that
      > the expression we would develope would be wrong.
      >
      > Either way.. this might be what you're looking for:
      >
      > <?php
      > $string = "var1: val11 val12 ... val1N var2: val21 val22 ... val2M ... varI:
      > valI1 ... valIJ";
      > $new_string = ereg_replace(" ([a-zA-Z0-9]+)\:", "\n\\1:", $string);
      > echo $new_string;
      > ?>
      >
      > --
      > Erik Andersson ( E.N.E IT - Australia )
      > http://www.eneit.com/
      > - Australian, high quality web hosting from AU$4.95, all features included.[/color]

      Comment

      Working...