Hello sandy105,
Yes, you have to allow for text such as “info - ” between the bracketed parts. But you don’t have to capture it. No need to capture the contents of the third bracketed part either, if you don’t need it:
#! perl use strict; use warnings; while (<DATA>) { / \[ ([^]]+) \] .* \[ ([^]]+) \] .* \[ [^]]+ \] \s+ (.*) /x or nex +t; my ($part1, $part2, $part3) = ($1, $2, $3); print "1: |$part1| 2: |$part2| 3: |$part3|\n"; } __DATA__ [part1-dateA] info - [..part2..] [..part3..] part4 [part1-dateB] log - [..part2..] [..part3..] part4
Output:
22:04 >perl 972_SoPW.pl 1: |part1-dateA| 2: |..part2..| 3: |part4| 1: |part1-dateB| 2: |..part2..| 3: |part4| 22:04 >
Note: I’ve added an /x modifier to the regex and whitespace within to make it easier to read.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: RegEX Doubt
by Athanasius
in thread RegEX Doubt
by sandy105
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |