#!/usr/bin/perl while (<>) { while($_ =~ s/^/?([^/]+)/?//) { print $1,"\n"; } }
It doesn't match them all in one match, but loops destructively against each line. It's also less preferable than a split, unless you're expecting input which contains slashes and doesn't otherwise match your criteria.
I realised when attempting this I have no idea how to make captured matches not overwrite each other - eg running /^(?:(\w+) ?)$/ against 'foo bar baz woz' returns only $1=woz; previous matches (foo etc) are overwritten.
If anyone knows how to alleviate that, it's driving me mental ..
Cheers
D
-----Original Message----- From: Mats Persson [mailto:mats@imediatec.co.uk] Sent: Friday, 8 April 2005 3:27 AM To: TM Users Subject: [TxMt] OT: Perl Compatible Regex problem I can't solve
OK, for way too many hours I have been trying to get this seemingly simple Perl compatible regex to work out, but I just can't seem to do it. I'm about to give up, move to a dark cave and shun computers for life. :(
The problem:
I have a string that is looking something like this: /a/b/c/d/ the string can be just /a/ or it can be /a/b/..../z/ very long.
I would like to catch all the various bits in this string [ /a/b/c/d/ ] as follows: $1 = /a/ $2 = b/ $3 = c/ $4 = d/
and so on for each added bit. The bits in between the "/" contains mainly [alphnums].
I've tried every regex version of this that I can think of and most don't return a damn thing, and others return the wrong things. A few days ago I thought I got this regex stuff, but now I'm in serious doubt.
I know that I can workaround the problem by doing other things, but it's become a bit of a burden on my mind. I'd like to know where I'm going wrong 'cause I can't see it at the moment and that drives me mad.
Extremely over the top grateful for any help. :)
Kind regards,
Mats
---- "TextMate, coding with an incredible sense of joy and ease" - www.macromates.com -
______________________________________________________________________ For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate