Deano Deano - 1 year ago 93
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download