Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Regex question

  1. #1
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts

    Regex question

    Is there any way, with a regex, to capture a pattern and use that match within the regex itself? Something along the lines of:

    Code:
    ~(one|two|three)some other text here(this part here should match the captured pattern, rather than just specifying one|two|three again)~

    Cheers muchly.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    What you're looking for is a back reference:
    http://www.php.net/manual/en/regexp....references.php
    Code:
    ~(one|two|three)some other text here\1~
    Last edited by kbluhm; 12-07-2010 at 10:30 PM.

  • Users who have thanked kbluhm for this post:

    MattF (12-07-2010)

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Cheers.


  •  

    Posting Permissions

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