http://www.pconline.com.cn/pcedu/empolder/wz/php/10111/15058.html

解决方案 »

  1.   

    1.'#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is':
    [a-z0-9\-_]+?匹配一組可以包括字母,数字,-,_的字符,其中[]内表示允許的字符,+表示字符數量為允許1到無窮個。加上?表示只有一組這樣的字符串。?紧跟在任何一个其他限制符 (*, +, ?, {n}, {n,}, {n,m})等后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,類推:
    ([a-z0-9\-_]+?\.)+?)就匹配類似sdf.和sdf.sdf.字符組,所以這個表達式匹配諸如abc.44d4,abc.abc.44d4等,而並非你所說的僅僅類似abc.44d4。2.'#\{([a-z0-9\-_]*?)\}#is'
    其中*表示0到無窮個。所以這個表達式還匹配空字符串
      

  2.   

    LXXXVII. Regular Expression Functions (Perl-Compatible)
    The syntax for patterns used in these functions closely resembles Perl. The expression should be enclosed in the delimiters, a forward slash (/), for example. Any character can be used for delimiter as long as it's not alphanumeric or backslash (\). If the delimiter character has to be used in the expression itself, it needs to be escaped by backslash. Since PHP 4.0.4, you can also use Perl-style (), {}, [], and <> matching delimiters. The ending delimiter may be followed by various modifiers that affect the matching. See Pattern Modifiers. PHP also supports regular expressions using a POSIX-extended syntax using the POSIX-extended regex functions.. Requirements
    Regular expression support is provided by the PCRE library package, which is open source software, written by Philip Hazel, and copyright by the University of Cambridge, England. It is available at ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/. Installation
    Beginning with PHP 4.2.0 this function are enabled by default. For older versions you have to configure and compile PHP with --with-pcre-regex[=DIR] in order to use these functions. You can disable the pcre functions with --without-pcre-regex. Runtime Configuration
    This extension does not define any configuration directives.Resource types
    This extension does not define any resource types.Predefined constantsTable 1. PREG constantsconstant description 
    PREG_PATTERN_ORDER Orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on. This flag is only used with preg_match_all().  
    PREG_SET_ORDER Orders results so that $matches[0] is an array of first set of matches, $matches[1] is an array of second set of matches, and so on. This flag is only used with preg_match_all().  
    PREG_OFFSET_CAPTURE See the description of PREG_SPLIT_OFFSET_CAPTURE. This flag is available since PHP 4.3.0 .  
    PREG_SPLIT_NO_EMPTY This flag tells preg_split() to only return only non-empty pieces.  
    PREG_SPLIT_DELIM_CAPTURE This flag tells preg_split() to capture parenthesized expression in the delimiter pattern as well. This flag is available since PHP 4.0.5 .  
    PREG_SPLIT_OFFSET_CAPTURE If this flag is set, for every occuring match the appendant string offset will also be returned. Note that this changes the return value in an array where very element is an array consisting of the matched string at offset 0 and it's string offset into subject at offset 1. This flag is available since PHP 4.3.0 and is only used for preg_split().  
    Examples
    Example 1. Examples of valid patterns
    /<\/\w+>/|(\d{3})-\d+|Sm/^(?i)php[34]/{^\s+(\s+)?$}
     
    Example 2. Examples of invalid patterns
    /href='(.*)' - missing ending delimiter /\w+\s*\w+/J - unknown modifier 'J' 1-\d3-\d3-\d4| - missing starting delimiter 
     
    Table of Contents
    Pattern Modifiers -- Describes possible modifiers in regex patterns
    Pattern Syntax -- Describes PCRE regex syntax
    preg_grep --  Return array entries that match the pattern 
    preg_match_all -- Perform a global regular expression match
    preg_match -- Perform a regular expression match
    preg_quote -- Quote regular expression characters
    preg_replace_callback -- Perform a regular expression search and replace using a callback
    preg_replace -- Perform a regular expression search and replace
    preg_split -- Split string by a regular expression
    User Contributed Notes
    Regular Expression Functions (Perl-Compatible)   
    [email protected]
    14-Jul-2000 10:59 
     
    ... so I find the solution for PCRE under Linux. Download the source code.
    Compile it with --with-pcre-regexmake parameter. It's working just fine
    with PHP 4.0.1pl2. One more time I learned: the safest (and the fastest)
    way is build your own code from the source. :-) 
     
    [email protected]
    24-Jul-2000 03:13 
     
    Please add a link from the ordinary regular expressions to these. Otherwise
    they are easy to miss, when looking for regex functions, due the
    abreviation. 
     
    [email protected]
    12-Mar-2001 04:09 
     
    Ever wondered how to use a function within a PCRE?  here's how:$content = preg_replace("/\*(\w+)\*/e",
    "lookupImageCode($1)", $content);This code replaces all instances of *text*, where text is a code for an
    image, with the output of function lookupImageCode().  The /e and the
    quotes around the function name and arguments are essential to make this
    work :-)I use this on one of my websites to query a database and cross-reference
    image filenames with special codes input by press release writers in our
    client's company.  They type the code of an image (displayed in a
    catalogue onscreen on the site's backend) and this little wonder of code
    changes it to an img src tag on the fly as the page is loaded.Enjoy!p.s.  thanks to the guys on #php who helped sort this out at 4am in the
    morning my time! (donut, jfk, cardinal)  Contact me if you like. 
     
    [email protected]
    21-Aug-2001 06:09 
     
    There is some really good/simple documentation of Perl regular expressions
    at http://extropia.com/tutorials/perl_faq.html#regular 
     
    [email protected]
    06-Mar-2002 11:33 
     
    If you're venturing into new regular expression territory with a lack of
    useful examples then it would pay to get familiar with this page:http://www.pcre.org/man.txt 
     
    [email protected]
    12-Mar-2002 12:56 
     
    Here's a translation of Friedl's email address matching regexp:http://www.killersoft.com/contrib/Friedl's perl original is available here:http://examples.oreilly.com/regex/ 
     
    [email protected]
    14-Jun-2002 09:47 
     
    This is the easiest tutorial for regular expressions I have found yet.
    Beginners should start here.
    This tutorial is originally written for Jscript, but I think everything
    applies to PHP.
    (I had to chop the following url into small pieces to be able to post it
    here)http://msdn.microsoft.com/library/en-us/script56/html/js56reconRegularExpressions.asp 
     
      

  3.   

    http://download.microsoft.com/download/winscript56/Install/5.6/W982KMe/CN/scd56chs.exe里面jscript部分有详细的正则表达式的中文说明。正则表达式决大多数通用