On 05/03/2013 04:54, Scott wrote:
Let's say I have a URL like this:
*http://www.mysite.com/section/subsection/Z3245678a34/*
And I want to turn it into an html link with the last element as the
highlighted text:
*<a
href="**http://www.mysite.com/section/subsection/Z3245678a34/**">Z3245678a34</a>*
*
*
What would I use as the search & replace values?
I hope to learn how to find substrings between certain characters
(like "/"). The "*Z3245678a34"* could be anything. "Unicorn123",
"mypage"," learningisfun4all".
If I were doing this regularly, I'd use a text filter, which is far more
powerful than the built-in search/replace dialog. An example is below.
As to places to find out about regular expressions, you will find
hundreds, but look for regex or PCRE
<http://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions> (the
variety used in BBEdit) rather than 'grep'.
#!/usr/bin/perl
use strict;
while (<>) {
if (m~http://(.+\b)(/?)~i) {
my $url = $&;
my @parts = split "/", $1;
my $link = pop @parts;
print qq~<a href="$url">$link</a>~;
} else {
print;
}
}
--
--
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.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.