You are here iC Home > Perl > Regular Expressions > Regex Recipes

Perl

2.3.1 Regex Recipes

20.11.2008
2.3 Regular Expressions [  up  ] - [ a - z ] - [ search PC ] - [ top ] 2.4 Files

Regex Recipe

You want to get back the complete word that has matched your search string.

e.g. fri → frische, as → asdf, fi → Fische, mei → meistens ...

#!/usr/bin/perl -w
use strict;

my $str = 'Fischer Fritz fischt meistens frische asdf oder foo Fische';

my $IN = $ARGV[0] || '';

if ($str =~ /.*\b(.*$IN.*?)\b.*/i) {
        print "$1\n";
}



See also:



Advanced search tips
2.3 Regular Expressions [  up  ] - [ top ] 2.4 Files



[ home ] - [ search ] - [ feedback ]

copyright by reto - created with mytexi