Deano Deano - 6 months ago 11
Perl Question

Perl oneliner regex

I have created this regex script online, to strip bracket out of string


I'm wondering if it is possible to run it on the shell as "perl oneliner"


# URL that generated this code:


$re1='.*?'; # Non-greedy match on filler
$re2='((?:\\/[\\w\\.\\-]+)+)'; # Unix Path 1

if ($txt =~ m/$re/is)
print $unixpath1;

I have tried

cat file | perl -wnE'say /((?:\\/[\\w\\.\\-]+)+)/g'
Unmatched ( in regex; marked by <-- HERE in m/(( <-- HERE ?:\\/ at -e line


You can use sed, but perl works too:

echo "[foo]" | perl -pe 's/[\[\]]//g'

Though i'm not sure why you want to use such a complicated regex just to remove braces.