[ddj] Dynamic backreferences?

Patrick Maynard patrickmaynard.bs at gmail.com
Thu Sep 26 10:50:07 UTC 2013


*Aiden:* RTFM. There's a link at the bottom. If that doesn't work, email
the list admins, not the entire list.

*Tarek:* Thanks again. To keep this conversation semifocused on something
on-topic, I'm curious: Have you used a script like this in your job or
daily life?

Bonus points if it was used for the reporting process. I'm always looking
for ideas to pass along.




On Thu, Sep 26, 2013 at 5:38 AM, Aidan Kelly <A.Kelly at gold.ac.uk> wrote:

>  Since there is no unsubscribe option - please remove me from the list
>
> It was interesting to me for a while but as I'm not a journalist it no
> longer is
> Looks good for journalists however.
>
> Aidan Kelly BA MA
> Senior Lecturer in Social Research Methods
> Department of Sociology,
> Goldsmiths, University of London
> Lewisham Way
> London SE14 6NW
>
> Email: a.kelly at gold.ac.uk
> Landline: 02070785019
> http://www.gold.ac.uk/sociology/staff/kelly/
>   ------------------------------
> *From:* data-driven-journalism-bounces at lists.okfn.org [
> data-driven-journalism-bounces at lists.okfn.org] on behalf of Tarek Amr [
> tarekamr at gmail.com]
> *Sent:* 26 September 2013 00:50
> *To:* List about Data Driven Journalism and Open Data in Journalism.
> *Subject:* Re: [ddj] Dynamic backreferences?
>
>   Hi,
>
>  Here is a python code that should do what you want
>
>  def colrepeat(text):
> ...     instr =  text.string[text.start()+1:text.end()-1]
> ...     outstr = '<'
> ...     for col in instr.split(','):
> ...             outstr = outstr + ','.join([col] * 3) + ','
> ...     outstr += '>'
> ...     return outstr
> ...
> re.sub('\<[a-z\,]+\>', colrepeat, 'I like <red,green,blue> and
> <white,black>')
>
>
>
>
> On Wed, Sep 25, 2013 at 9:15 PM, Patrick Maynard <
> patrickmaynard.bs at gmail.com> wrote:
>
>> Is there a simple way to make a regular expression generate its own back
>> references?
>>
>>  For example, if I have strings "this is a <red,blue,green> set" and
>> "this is a <red,brown,blue,green,brown> string" (and several other strings
>> that vary in the number of color instances), and I know that the brackets
>> will always be exclusively wrapped around the comma-delimited color list,
>> can I write a single replacement pattern that will repeat each color three
>> times before going to the next color?
>>
>>  I realize that there are a ton of much better, non-big-hammer ways of
>> doing this. I'm just curious about this as a sort of academic exercise at
>> this point. Is there a way to accomplish this strictly with regex?
>>
>>  -- Patrick
>>
>>
>>
>> _______________________________________________
>> data-driven-journalism mailing list
>> data-driven-journalism at lists.okfn.org
>> http://lists.okfn.org/mailman/listinfo/data-driven-journalism
>> Unsubscribe: http://lists.okfn.org/mailman/options/data-driven-journalism
>>
>>
>
>
>  --
> Best Regards
> Tarek Amr
>
> http://tarekamr.appspot.com/
>
>
> _______________________________________________
> data-driven-journalism mailing list
> data-driven-journalism at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/data-driven-journalism
> Unsubscribe: http://lists.okfn.org/mailman/options/data-driven-journalism
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/data-driven-journalism/attachments/20130926/ecac8b8f/attachment-0001.html>


More information about the data-driven-journalism mailing list