in reply to Escape special chars in a path
G'day ovedpo15,
I'd use a bracketed character class. A negated one is possibly the easiest. If you want to individually specify special characters, see "Special Characters Inside a Bracketed Character Class". Here's an example.
#!/usr/bin/env perl use strict; use warnings; use Test::More; my @tests = ( ['a!b@c#', 'a\!b\@c\#'], ['{d}e(f)', '\{d\}e\(f\)'], [q{g"h'i}, q{g\"h\'i}], ['[/].\\', '\[/\].\\\\'], ); plan tests => 0+@tests; my $re = qr{([^0-9A-Za-z./])}; for my $test (@tests) { my ($got, $exp) = @$test; $got =~ s/$re/\Q$1/g; ok $got eq $exp; }
Output:
1..4 ok 1 ok 2 ok 3 ok 4
Extend those tests with real pathnames from your application.
You may need different regexes for rsync and cp (depends on whether "except" should be "accept" or "expect" :-)
— Ken
|
---|