A
advice please wireless 802.11 on RH8
I'm pretty good at regexes- at least for most common uses. But
although I can brute force a solution here I'm not happy with it!
Lets say we have an array like
my @a = qw(10 20 22 23 25);
and some text like
'44,33,4.44.64.10,32,25,88,20,6,55'
and I want a regex that replaces any number in the string with say
'XX', as long as that number is not in the array @a, yielding:
$_ = 'XX,XX,XX.XX.XX.10,XX,25,XX,20,XX,XX'
The most *elegant* approach I've dreamed up is to join the array with
OR (|), then somehow use that to compare in the text. But I'm not sure
how to negatively compare.
my $a = join '|',@a;
s/(something)($a)/XXX/g;
I think this may be one of those oddball assertions that I never
mastered.
My other idea was to @t = split /,/
then iterate over each element with
grep /^$element$/,@t
but that ain't so pretty either..
Can someone give me a nudge in the right direction to do this in A
single, simple, elegant regex with no array conversions or looping? I
can usually dream one up but not this time!
although I can brute force a solution here I'm not happy with it!
Lets say we have an array like
my @a = qw(10 20 22 23 25);
and some text like
'44,33,4.44.64.10,32,25,88,20,6,55'
and I want a regex that replaces any number in the string with say
'XX', as long as that number is not in the array @a, yielding:
$_ = 'XX,XX,XX.XX.XX.10,XX,25,XX,20,XX,XX'
The most *elegant* approach I've dreamed up is to join the array with
OR (|), then somehow use that to compare in the text. But I'm not sure
how to negatively compare.
my $a = join '|',@a;
s/(something)($a)/XXX/g;
I think this may be one of those oddball assertions that I never
mastered.
My other idea was to @t = split /,/
then iterate over each element with
grep /^$element$/,@t
but that ain't so pretty either..
Can someone give me a nudge in the right direction to do this in A
single, simple, elegant regex with no array conversions or looping? I
can usually dream one up but not this time!