1833405 Members
3067 Online
110052 Solutions
New Discussion

Perl - REGEXP Question.

 
SOLVED
Go to solution
Josef Ziegler
New Member

Perl - REGEXP Question.

Im working on a search engine in pearl.
I looking for a REGEXP funktion using the string REALY found and not what I was looking for.

This is the because lower and upper case handling.
The found words will get highlighted, and if the user entered it lowercase but in the file its uppercase we like to highlighte it uppercase, which is not working in our code.

i.e.
if($Wort01 =~ /.+/) {$_ =~ s/$(Wort01)/$1<\/span>/g}
3 REPLIES 3
H.Merijn Brand (procura
Honored Contributor
Solution

Re: Perl - REGEXP Question.

$Wort01 and s{\b($Wort01)\b}{$1}/gi;

several remarks

1. $(Wort01) will not match what you expect, ($Wort01) might
2. use /i to ignore case
3. use s{}{} or any other brace type seperator when working with regex that uses / to increase readability
4. $Wort01 =~ /.+/ is about the most inefficient I've seen for testing truth. You might consider $Wort01 =~ m/\S/

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: Perl - REGEXP Question.

Oh, and forgot, since $_ is the default for many functions and operators, you'll increase readability IMHO, by using it like that, so

$_ =~ s{}{};

is the same as plain

s{}{};

Perl has already enough line noise as it is

Enjoy, Have FUN! H.Merijn. [ who just happens to love perl's line noise ]
Enjoy, Have FUN! H.Merijn
Josef Ziegler
New Member

Re: Perl - REGEXP Question.

Thx procura,
My main fault was a simple typo
$(Wort01) instead to ($Wort01).

But Thanks tooo for the other tips, they could make my code much easier to read....