> Da: Ronald J Kimball <[email protected]>
> Risposta: <[email protected]>
> Data: Mon, 5 Oct 2009 13:16:12 -0400
> A: <[email protected]>
> Oggetto: Re: Hi all
>
>
> On Mon, Oct 05, 2009 at 09:06:28AM -0700, LollyMap wrote:
>>
>> Hi all, I'm doing a big project, with a lot of html text to transform
>> in simple text.
>> I'd like to ask you if you find something wich could help me.
>> I have this string:
>> [[Papal Apartments]], some of the [[Roman Catholic Church|Catholic
>> Church's]] government offices,
>>
>> it's written as you see, with all "[".
>> So I need to cancel "[[" when they have only one term, as "Papal
>> Apartments" but in the second case I have a big problem. in:
>> [[Roman Catholic Church|Catholic Church's]]
>> I need to keep "Roman Catholic Church" and delete Catholic Church's.
>
> I take it you are removing Wiki-markup from text? Are you sure you want to
> keep the first term? It appears that the first term is the article title,
> and the second term is the link text. To preserve the actual rendered
> text, I think you'd want the latter...
>
>
> Anyway, try this to preserve the first term:
>
> Find
> \[\[([^\]\|]+)(?:\|[^\]]+)?\]\]
>
> Replace
> \1
>
>
> To preserve the second term, you'll need two different substitutions:
>
> Find
> \[\[([^\]\|]+)\]\]
>
> Replace
> \1
>
> Find
>
> \[\[[^\]\|]+\|([^\]]+)\]\]
>
> Replace
> \1
Thank you Roland, I don't know how to thank you !
You're right, the second term is the one I need !
Anyway it works !
>> I tried with \ | . + \ ] \ ] , but I did not work, as it keeps from |
>> Catholich Church's to the end of the line where there's another couple
>> of "]]" .
>> How to tell it to stop when it finds the FIRST couple of ]] ?
>
> You should either use a more precise character class in place of the
> period, as I did above with [^\]], or use a non-greedy quantifier:
> \[\[(.+?)(?:\|.+?)\]\]
>
> Each approach has advantages and disadvantages, but either should work in
> this case.
>
>
>> Second question is: how to do all times the same changes, can I store
>> more than one find and replace toghether and let it do all
>> automatically ? I save each one , but I'd like it applies all , maybe
>> to a new group of files. As were a recorded macro, for example.
>
> One way to do this would be to write a script that performs all the
> substitutions. Here's an example in Perl, my own language of choice:
>
> #!perl
>
> # clear the input record separator; targets may be line-wrapped, e.g.
> # [[Example Article|an example
> # article]]
>
> $/ = undef;
>
> while (<>) {
> s/\[\[([^\]\|]+)\]\]/$1/g; # wiki-link with no link text
> s/\[\[[^\]\|]+\|([^\]]+)\]\]/$1/g; # wiki-link with custom link text
> print;
> }
>
> __END__
>
> If you prefer another language (AppleScript is another obvious choice), ask
> the list and someone will likely provide an example.
>
> Ronald
I'll try, even if I don't know Perl.
Anyway I'll wait if someone could help me with AppleScript, and I'll try to
do myself.
Fabrizio
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
-~----------~----~----~----~------~----~------~--~---