Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: RegEX Doubt

by Athanasius (Archbishop)
on Aug 19, 2014 at 12:07 UTC ( [id://1097969]=note: print w/replies, xml ) Need Help??


in reply to RegEX Doubt

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,

Replies are listed 'Best First'.
Re^2: RegEX Doubt
by sandy105 (Scribe) on Aug 19, 2014 at 15:58 UTC

    thank you much ..for anyone referencing later x is a modifier to allow white spaces .possible use cases include commenting regex and spacing to improve legibility

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1097969]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-25 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found