Forum Moderators: coopster

Message Too Old, No Replies

regex capture

         

gb_dev

7:21 pm on Nov 15, 2006 (gmt 0)

10+ Year Member



String to match against: An_Park_Hotel_1__3_1_2_3.mpg

regex:
[code]
preg_match('/^(.*)_([0-9]+)__([0-9])(_[0-9]+)+(\.mpg)$/i', $file, $matches)
[\code]

Array
(
[0] => An_Park_Hotel_1__3_1_2_3.mpg
[1] => An_Park_Hotel
[2] => 1
[3] => 3
[4] => _3
[5] => .mpg
)

I looking to capture:

[4] => _1_2_3

alfaguru

7:59 pm on Nov 15, 2006 (gmt 0)

10+ Year Member



Change the expression to '/^(.*)_([0-9]+)__([0-9])((_[0-9]+)+)(\.mpg)$/i'

ie. put an extra set of parentheses round the expression you actually want to capture. The substring you want should then be in item 4 of the array and the one you're getting now in item 5. (I think that's the way round they go, but this is from memory so ...)