d.Grudder
d.Grudder

Reputation: 160

Read file using regex Perl

I have a configuration file name camera.start . The configuration looks like this :

video4linux2 -i /dev/video0 -vcodec

My question is, how can we read the /dev/video0 only in Regex? But know this that the value /dev/video0 is always changing. So i cannot read that file using [characters] modifiers. Any suggestion on how to read this configuration file using regex? Any help would be appreciated.

Upvotes: 0

Views: 77

Answers (3)

php-dev
php-dev

Reputation: 7156

The string can be parsed by splitting on ' ' caracter.

But if you still want a regex, here you are

my $str = "video4linux2 -i /dev/video0 -vcodec";
($i) = ($str =~ m/video4linux2 -i (\S+) -vcodec/);

print "$i\n";  # '/dev/video0'

Upvotes: 2

Robin
Robin

Reputation: 9644

No need for regex, just split on a space character:

my $data = 'video4linux2 -i /dev/video0 -vcodec';

my @values = split(' ', $data);

print @values[2];

Upvotes: 4

Miller
Miller

Reputation: 35198

my $str = 'video4linux2 -i /dev/video0 -vcodec';

my $dev = (split ' ', $str)[2];

print $dev;

Upvotes: 3

Related Questions