excel - How to remove text within brackets in a string while still keeping the other text? -
my $book = spreadsheet::read->new(); $book = readdata ('d:\profiles\jmahroof\desktop\scheduled_build_overview.xls'); $cell = "cd7"; $n = "1"; $send = $book->[$n]{$cell}; $send =~ s/\(/ /g; $send =~ s/\)//g;
i have above code gets data excel file , picks out text specified cell , removes brackets string. need able remove within brackets including brackets while leaving rest of text. format of string following : text(text)
$send =~ s/\(.*?\)//;
explained:
s/
search \
escapes bracket comes next seen part of code if not escaped. (.*?\)
here searching use non-greedy .*? match last bracket again last bracket escaped \
/
begins replace function search /
ends search , replace.
so search (*) , replace nothing.
explaing non greedy vs greedy.
.* being greedy match until last )
found
so if have string((substring)end)
then s/(.*)//
go first (
last )
leaving string
non greedy not, begin first (
first )
leaving stringend)
lazy , match ask ( ) greedy match grab everything, if have (string)(())((strings))()()strings)strings)
Comments
Post a Comment