http://www.perlmonks.org?node_id=1012032


in reply to Extracting Strings - Special Cases

Hello rajkk04, and welcome to the Monastery!

i want to extract only 4 letters (alphanumeric) in the complete text.

Assuming this means: Match the first alphanumeric word of exactly 4 characters appearing between double quotes:

#! perl use strict; use warnings; my $s = '"perl"monks'; $s =~ m{ " (\w{4}) " }x; print $1, "\n" if $1;

Output:

23:31 >perl 475_SoPW.pl perl 23:31 >

See “Quantifiers” under perlre#Regular-Expressions.

Update: If you need to match strictly alphanumeric characters only (no punctuation characters), change \w in the regex to [A-Za-z0-9].

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,