Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl's regular expressions

Status
Not open for further replies.

gammaman1

Programmer
Jun 30, 2005
23
US
using perl, how would i get it to erase everything up to and including the first bracket [ ?

I have this, but it only erases up to the [. I need the bracket removed as well.

for($i=0;$i<@mylist;$i++)
{
@mylist[$i] =~ s/[^]]*//;
}

any ideas?
thanks,
gammaman
 
i tried adding the \], but it's still displaying the ]. for example:
input: [testtest] test test test [testtest]
output: ] test test test [testtest]

for($i=0;$i<@mylist;$i++)
{
@mylist[$i] =~ s/[^\]]*//;
}

did i put it in the right spot?

thanks,
gammaman
 
Nope :) - you need `any number of non-brackets followed by a bracket'
Code:
@mylist[$i] =~ s/[^]]*\]//;
I *think* that'll do it - it's late.
 
Code:
[b]#!/usr/bin/perl[/b]

$_ = 'this string [ has many [ brackets in it with a ] few ] closing ] also.';

[b][red]s/[^[]+\[//;[/red][/b]

print;

outputs:-
has many [ brackets in it with a ] few ] closing ] also.

... notice this only removes up to, and including, the first opening square bracket


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top