?
Solved

Regex question ?

Posted on 2007-07-22
2
Medium Priority
?
220 Views
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 & _
Next

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

User ID/1
Username/2

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

Thanks very much.
0
Comment
Question by:phpdotnet
2 Comments
 
LVL 4

Accepted Solution

by:
punkstar earned 2000 total points
ID: 19543060
<?php
$subject = 'For $i = 1 To $User[0][0] Step 1
                  "User ID: " & $User[$i][1] & @CRLF & _
                  "Username: " & $User[$i][2] & @CRLF & _
Next';
preg_match_all('/(.*): " & \\$User\\[\\$i\\]\\[([\\d]*)\\]/', $subject, $result);
print_r($result);
?>

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

Author Comment

by:phpdotnet
ID: 19543949
Nah, that's what I need. Thanks for your answer :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 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