Rory Winston wrote:
>> I have a question re: a regex that has had me stumped. I have a CGI script
> that generates a string of concatenated user ids, such as "1|2|86|907|7|"
> etc. I had a regex that extracts the uids like so:
>> print("id=$1\n") while ( $id_string =~ /(\d+)|/g );
>> But this doesnt work - I always get an extraneous (empty) match for every
> id, and an extra empty match at the end! Is this because it matches the '|'
> character second time round or something? it does work if I do:
>> print("id=$1\n") while ( $id_string =~ /(\d+)(|)/g );
>> I know, I know - RTFM for regexes - I have a copy of Friedl's "Mastering
> Regular Expressions" on my shelf that I'm going to get around to reading one
> of these days, but until then, can anyone shed any light?
1. | are special in re's so you probably want to escape it like \|
2. This is simple enough not to require a re, see split()
3. I don't know perl so here's the python equivalent:
for id in "1|2|86|907|7".split("|"):
print "id=" + id
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!