Re: Antwort: [PBML] perl substitution
- On Jul 2, 2007, at 4:29 PM, Scott Mayo wrote:
> I am going to ask this again since I don't think that I asked what IYou need to use ()'s to capture the parts of the regular expression
> needed to the first time. I tried the suggestions, but they did
> not do
> what I wanted. I do appreciate those helps though. I am going to
> a log file and here is what I basically want to do:
> I want to pull off the first bracketed info into a variable and leave
> the rest in another variable.
match that you're interested in keeping:
perl -w -e '
$line = "[the time is 1:59:00] [Scott] How are you? [Allie] Fine
$line =~ m/^(\[[^]]*\])?(.*)$/;
print "bracketed part: $1\n";
print "remaining line: $2\n";
bracketed part: [the time is 1:59:00]
remaining line: [Scott] How are you? [Allie] Fine today.
> Here are a couple of other things. There may be only one set ofI very nearly gave you a variation of the standard "don't ask us to
> bracketed info and there may be none at all or there may be a lot of
> sets of bracketed info. So I could have the following in the file
> is 3 lines in total:
> [the time is 1:59:00] [Scott] How are you? [Allie] Fine today.
> Thank you for coming.
> [Tell] Hey there.
> After parsing my lines I could have the following info.
> $line1 = [the time is 1:59:00]
> $line1 = [Scott] How are you? [Allie] Fine today.
> $line2 = Thank you for coming.
> $line3 = [Tell]
> $line3 = Hey there.
> Thanks again.
> Scott Mayo
> System Administrator
> Bloomfield Schools
do your homework" when I noticed your .k12. address, but I decided to
give you the benefit of the doubt when I got to your signature.
The '?' in the regexp means that the first part is optional (i.e.,
can match zero or one time).
You might also have to check "if (defined $1)" to know whether there
was a "first part" or not.
Rob Biedenharn http://agileconsultingllc.com