Hi,
I'm trying to get one field out of many as follows:
A string of multiple fields separated with "/" characters:
"/ab=12/cd=34/12=ab/34=cd/ef=pick-this.one/gh=blah/ij=something/"
I want to pick up the field "ef=pick-this.one" which has no regular pattern except it starts with "ef=xxxx" and ends to a "/"
I wrote a little script to get it, but I'm just wondering if there is some better way of doing this(using Perl):
$ ./matchtest.pl
Unwated beginning: /ab=12/cd=34/12=ab/34=cd/
Unwated ending: /gh=blah/ij=something/
Wanted string: pick-this.one
Using this code:
#!/usr/bin/perl
my($text) = "/ab=12/cd=34/12=ab/34=cd/ef=pick-this.one/gh=blah/ij=something/";
my($prefix,$string,$postfix) = $text =~ m/(.*\/)(ef.*?)(\/.*)$/;
print "Unwated beginning: $prefix\n";
print "Unwated ending: $postfix\n";
$string =~ s/ef=//g;
print "Wanted string: $string\n";