Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Extracting Strings - Special Cases

by Athanasius (Chancellor)
on Jan 07, 2013 at 13:35 UTC ( #1012032=note: print w/replies, xml ) Need Help??


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,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012032]
help
Chatterbox?
[stevieb]: 16.96 hours of runtime of a Raspberry Pi on a 12v, 7.2Ah battery :) Now to watch now long it takes to recharge the battery completely with my 18v solar cells in the sun :)
[stevieb]: my high-range estimate was 18 hours
[stevieb]: battery was at about 95% capacity when the test began
[stevieb]: in the meantime while it was on battery, I got my shift register issues fixed, as well as certain interrupt issues

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2017-03-26 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (315 votes). Check out past polls.