#!/usr/bin/perl use strict; use warnings; my $bal; $bal = qr /[^()]* (?: [(] (??{ $bal }) [)] )* [^()]*/x; while (<DATA>) { chomp; print $& while /$bal/g; print "\n"; } __DATA__ (1.3.56.84 56.38.m.26) (56.2.3.59) ((one)(two)) ((one(two)) ((one)(two) (one)(two)) ((one)two))
Running this gives:
1.3.56.84 56.38.m.26 (56.2.3.59) ((one)(two)) (one(two)) (one)(two) (one)(two) ((one)two)
Abigail
In reply to Re: Removing only the first instance with RegEx
by Abigail-II
in thread Removing only the first instance with RegEx
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |