Results 1 to 3 of 3

Thread: preg regex end parameter /Ui

  1. #1
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default preg regex end parameter /Ui

    http://www.php.net/manual/en/functio...lace.php#77255

    That's the example I am using (adapted some).

    I don't now what the /Ui means after the regex. I am guessing it's some sort of parameter.

    From testing it looks like it makes it "not greedy" so it finds the shortest string possible rather than finding the farthest instances to match. Removing it makes it take a longer string, rather than the shortest possible.

    Is this correct?


    And is there a list of these parameters somewhere?

    I looked around but couldn't find a reference on this specifically.


    Thanks...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,875
    Thanks
    92
    Thanked 97 Times in 95 Posts

    Default

    The U and the i are listed after delimiters. These are known as modifiers in that they modify how PCRE operates to some degree. They can also be listed next to each other as in the example you mentioned.

    For example:

    PHP Code:
    <?php
    $text 
    "text--hn-tact-----hn---tact";
    $text=preg_replace('/(teXt).*?(tact)/Ui','',$text);
    echo 
    "$text";
    ?>
    the result is an empty string.

    This will look for the word text or TEXT or TeXt all the way up to the word tact. normally .*? will match everything from "text" to the very next "tact" it comes across, but in this example the quantifier greediness has been inverted, so the ? will now match up to the last tact instead. I usually don't bother with the /U modifier.

    /U = inverts the greediness of the quantifiers.
    /i = makes it case insensitive.

    They are placed after the delimiter and before the ending quote and are case sensitive.

    You can read more on modifiers here.

    Pretty much everything else can be found here.

    I added the extra info for whoever is curious
    Last edited by james438; 06-19-2010 at 07:24 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. The Following User Says Thank You to james438 For This Useful Post:

    djr33 (06-19-2010)

  4. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Thanks, James! Perfect answer and I'll read up on that now. Regex still looks like hieroglyphics to me, but I'm trying to get used to it. When it works, it's great...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •