Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Regex for replacing capture group content using perl

by NetWallah (Canon)
on Jul 07, 2019 at 01:29 UTC ( [id://11102488]=note: print w/replies, xml ) Need Help??


in reply to Regex for replacing capture group content using perl

Welcome to the Monastery!

Please see Writeup Formatting Tips to format your post better.

Try this:

use strict; use warnings; local $/="\n\n"; while (<DATA>){ if ( my ($prefix,$suffix)=m/\[WinEventLog:.+index = (\w+)_(pr|np)\s +*$/s){ # print "$prefix\_$suffix found .. replacing...\n"; s/index = $prefix\_$suffix\s*$/index = window_$suffix\n\n/; } print ; } __DATA__ [WinEventLog://Application] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = CNDO_pr [WinEventLog://Security] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = CGWS_pr [WinEventLog://System] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = DMRW_pr [WinEventLog://ForwardedEvents] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = NENP_pr [WinEventLog://Setup] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = EOFK_pr [WinEventLog://Application] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = FDWD_np [WinEventLog://Security] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = ASKD_np [WinEventLog://System] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = JMSF_np [WinEventLog://ForwardedEvents] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = JCCD_np [WinEventLog://Setup] checkpointInterval = 5 current_only = 0 disabled =0 start_from = oldest index = HSMS_np

                "From there to here, from here to there, funny things are everywhere." -- Dr. Seuss

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-25 20:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found