SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg question: the meaning of '#'....?

    Hi

    I have often seen this sign used in regexp:

    #

    However, I haven't found what it means...

    anyone?


  2. #2
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    New Jersey
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing you're talking about the # delimiter. If so, know that PHP/PCRE supports the same delimiters as Perl, among them:

    Code:
    /pattern/    (common)
    #pattern#    (common when using URLs or HTML tags that contain an /)
    ~pattern~
    {pattern}
    |pattern|
    etc.
    After the pattern comes optional modifiers, such as 'm', 'i', 'e', 'x', and 's'. These modifiers modify the pattern in some way; for instance, /pattern/i makes the pattern case-insensitive.

    That's about it. Ask away if anything troubles you.

  3. #3
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot for your answer

    that definitly helps.

    # avoids to escape / if I follow you correctly (\/)

    about the optional modifiers: they will modify the whole pattern right? But can I still use modifiers to operate on parts of the pattern?

    like (.+)/i

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    New Jersey
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by duuudie
    thanks a lot for your answer :)

    that definitly helps.
    You're welcome.
    Quote Originally Posted by duuudie
    # avoids to escape / if I follow you correctly (\/)
    Yes. To match any text between <b> and </b>, you could use the following patterns:
    Code:
    /<b>(.*?)<\/b>/i
    #<b>(.*?)</b>#i
    Which pattern looks easier to use without forgetting to escape the /?

    Quote Originally Posted by duuudie
    about the optional modifiers: they will modify the whole pattern right?
    Yes.

    But can I still use modifiers to operate on parts of the pattern?

    like (.+)/i
    Of course. To modify a subpattern, enclose it between (?i)pattern(?i), or using non-capturing paranthesis using (?i:pattern) -- where i represents the modifier you wish to turn on. For instance, to match foobar, FOObar, or any case variant of foo, you could use:
    Code:
    /(?i)foo(?i)bar/
    /(?i:foo)bar/
    /[fF][oO][oO]bar/

  5. #5
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you rock!

    thanks a lot

    Do you have, by chance, a few links to provide? I have a few urls about RegEx but I would be happy to learn more about it. Especially when it comes to use them with PHP.


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
  •