ereg_replace

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

    ereg_replace

    I would like find all occurences of "ABC" which are not followed by "123"
    and replace them with "abc". For example:
    "ABC dd" -> "abc dd"
    "ABC123" -> "ABC123"
    "ABC 123" -> "abc 123"

    Give me a recipe, please. I've spent 2 hours googling for it.


    -tt.
  • Chung Leong

    #2
    Re: ereg_replace


    Tomek Toczyski wrote:[color=blue]
    > I would like find all occurences of "ABC" which are not followed by "123"
    > and replace them with "abc". For example:
    > "ABC dd" -> "abc dd"
    > "ABC123" -> "ABC123"
    > "ABC 123" -> "abc 123"
    >
    > Give me a recipe, please. I've spent 2 hours googling for it.
    >
    >
    > -tt.[/color]

    preg_replace_ca llback() is your friend. Use preg_replace_ca llback().

    Example:

    function lowercase_callb ack($m) {
    return strtolower($m[0]);
    }

    $s = preg_replace_ca llback('/[A-Z]+(?![A-Z\d])/', 'lowercase_call back',
    $s);

    Comment

    • Mark ??;-\)

      #3
      Re: ereg_replace

      This will find the files you specified:
      (^[A][B][C]) ([1-9a-zA-Z]*)

      I tried finding the right substitution syntax, but didn't really find a
      solution. It looks like maybe using tr/ to translate between the UC and LC
      would be a start. Look at http://www.comp.leeds.ac.uk/Perl/sandtr.html
      Unfortunately I don't have BASH on this computer so I can't really work more
      on this.

      -Mark


      "Tomek Toczyski" <guf@kajak.org. pl> wrote in message
      news:Pine.GSO.4 .61.05112302463 30.28301@ztest. ..[color=blue]
      >I would like find all occurences of "ABC" which are not followed by "123"
      > and replace them with "abc". For example:
      > "ABC dd" -> "abc dd"
      > "ABC123" -> "ABC123"
      > "ABC 123" -> "abc 123"
      >
      > Give me a recipe, please. I've spent 2 hours googling for it.
      >
      >
      > -tt.[/color]


      Comment

      • Tomek Toczyski

        #4
        Re: ereg_replace

        Chung Leong:[color=blue]
        > preg_replace_ca llback() is your friend. Use preg_replace_ca llback().
        >
        > Example:
        >
        > function lowercase_callb ack($m) {
        > return strtolower($m[0]);
        > }
        >
        > $s = preg_replace_ca llback('/[A-Z]+(?![A-Z\d])/', 'lowercase_call back',
        > $s);[/color]

        It works. Thanks a lot.

        Comment

        Working...