Reputation: 160
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
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
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
Reputation: 35198
my $str = 'video4linux2 -i /dev/video0 -vcodec';
my $dev = (split ' ', $str)[2];
print $dev;
Upvotes: 3