Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: String extract 2

by farang (Hermit)
on Jul 24, 2014 at 12:35 UTC ( #1094903=note: print w/ replies, xml ) Need Help??


in reply to String extract 2

You can use a negated character class to match up until the included chars in the class are found.

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; my @test_cases = ( 'KP_what_I_want(but_not_this', 'KP_what_I_want nor_this', 'KP_ nor_any_of_this', 'and this will not match', ); for my $line (@test_cases) { my ($exp) = $line =~ m/ KP_ # Required. ( [^ (]* ) # Capture until space # or left paren. /xi; if (defined $exp) {say "<$exp>"} else {say 'NO MATCH'}; } __END__ <what_I_want> <what_I_want> <> NO MATCH


Comment on Re: String extract 2
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1094903]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-12-20 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls