SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: regexp question

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question regexp question

    Is there a way to get the grouping effect or parentheses without having them be included in the array of subpatterns?

    For example, is there a way to do this:
    PHP Code:
    $regexp '/([0-9]+)(\.[0-9]+)?/'
    but have it so the second set of parentheses doesn't get included in the set of subpatterns.

    thanks

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (stuff in here is stored)
    (?:stuff in here isn't stored)

    Basically ?: makes it non-storing.

    Does that answer it?
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup. thanks! Also, is there a limit to how long a regexp can be, in characters?

  4. #4
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    '/^[a-z0-9_-]{3,255}$/i'
    For example

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2002
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I meant, the regular expression itself. For example, could you make a regular expression with hundreds of words using the OR operator? such as '/(word1|word2|words3|etc)/i' or is there a limit to how long they can be?

    thanks anyway

  6. #6
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I pretty sure there isn't a hard limit. I've never heard of one at least.

    Now, would that be the best option? Not sure... breaking the problem into several steps may be more efficient but just as easily could be impractical or slower.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


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
  •