regex - Perl Pattern Matching Question -
i trying match patterns in perl , need help.
i need delete string matches [xxxx] i.e. opening bracket-things inside it-first closing bracket occurs.
so trying substitute space opening bracket, things inside, first closing bracket following code :
if($_ =~ /[/) { print "in here!\n"; $_ =~ s/[(.*?)]/ /ig; }
similarly need match i.e. angular bracket-things inside it-first closing angular bracket.
i doing using following code :
if($_ =~ /</) { print "in here!\n"; $_ =~ s/<(.*?)>/ /ig; }
this how not seem work. sample data below :
'joanne' <!--her name not contain "kathleen"; see section "name"--> "'jo'" 'rowling', obe [http://news bbc co uk/1/hi/uk/793844 stm caine heads birthday honours list] bbc news 17 june 2000 retrieved 25 october 2000 , [http://content scholastic com/browse/contributor jsp?id=3578 jk rowling biography] scholastic com retrieved 20 october 2007 better known 'j k rowling' ,<ref name=telegraph>[http://www telegraph co uk/news/uknews/1531779/bbcs-secret-guide-to-avoid-tripping-over-your-tongue html daily telegraph, bbc's secret guide avoid tripping on tongue, 19 october 2006] british <!--do not change "english" or "scottish" until issue resolved --> author best known creator of [[harry potter]] fantasy series, idea conceived whilst on train trip manchester london in 1990 potter books have gained worldwide attention, won multiple awards, sold more 400 million copies , been basis popular series of films, in rowling had creative control serving producer in 2 of 7 installments [http://www businesswire com/news/home/20100920005538/en/warner-bros -pictures-worldwide-satellite-trailer-debut%c2%a0harry business wire - warner bros pictures mentions j k rowling producer ]
any appreciated. thanks!
$_ =~ /someregex/
not modify $_
just note, $_ =~ /someregex/
, /someregex/
same thing.
also, don't need check existence of [ or < or grouping parenthesis:
s/\[.*?\]/ /g;
s/<.*?>/ /g;
will job want.
edit: changed code match fact you're modifying $_
Comments
Post a Comment