Regex question ?

Posted on 2007-07-22
Last Modified: 2008-07-03
If I have some text like this :

For $i = 1 To $User[0][0] Step 1
                  "User ID: " & $User[$i][1] & @CRLF & _
                  "Username: " & $User[$i][2] & @CRLF & _

Can anyone please show me an example of how to use regex to print :

User ID/1

( where the number after the / is the number in the bracket )

Thanks very much.
Question by:phpdotnet
    LVL 4

    Accepted Solution

    $subject = 'For $i = 1 To $User[0][0] Step 1
                      "User ID: " & $User[$i][1] & @CRLF & _
                      "Username: " & $User[$i][2] & @CRLF & _
    preg_match_all('/(.*): " & \\$User\\[\\$i\\]\\[([\\d]*)\\]/', $subject, $result);

    Is that what you're looking for? If its not, can you give a larger example of what your $subject data looks like.

    Author Comment

    Nah, that's what I need. Thanks for your answer :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now