[Koha-devel] Perl regex

Bernardo Rechea brechea at earthlink.net
Tue Jan 20 20:05:35 CET 2004


Hi, Paul,

I just subscribed to this mailing list, but saw your message in the 
archives:

> We have the following strings in templates : <a 
> href="/koha/search.pl">search</a> the library.
> 
> In the translation file for french, we have :
> search    chercher
> So, the regexp :
> $line =~ s/(\W)$text(\W)/$subst/g;
>
>  that is WRONG !!! (search.pl must not be replaced !)
> 
> & I couldn't find the regexp that could work better.
> [...]
> but i'm still looking for a better solution to do this.
> 
> Note : remembre we can also have <img src="XX" alt="search"> and this 
> search is to be replaced... 

Try this:

$line =~ s/(<=\W)$text(?!\.pl)/$subst/g;

By the way, should the original regex you posted have been

> $line =~ s/(\W)$text(\W)/$1$subst$2/g; ?

Otherwise you would be deleting one character before and one character after every "search". Anyway, the above regex should substitute
any $text that is preceded by a non-word char and not followed by '.pl'. Since the message is almost a week old, you probably have
figured it out by now, but I thought I'd give it a try, because I can't resist a regex quiz ;-D

I guess I should introduce myself: my girlfriend and I volunteer for the German Library School of Boston. Recently it was decided
to automate library circulation and have as well an electronic catalog. I use Linux at work and at home, and after some searches we found
a nice open source project that did what we needed, Koha, so here we are. We have installed it
on two laptops and it's working mostly fine save for some glitches. But I guess I should talk about that in the Koha mailing list,
not here.

Bernardo Rechea





More information about the Koha-devel mailing list