Regex 如何将路径拆分为特定的层次结构

Regex 如何将路径拆分为特定的层次结构,regex,perl,perl-module,regex-negation,Regex,Perl,Perl Module,Regex Negation,我想使用Perl来分割路径 funit/pipe/str/str32/gt/split 最多 使用正则表达式。看起来您只需要父目录的路径;是这样吗?我不会称之为“分裂”道路 对使用正则表达式模式的限制是真正的限制,还是您认为这是最好的方法 下面是一个程序,它使用Path::Tiny来执行您的请求 use strict; use warnings 'all'; use feature 'say'; use Path::Tiny; my $path = Path::Tiny->new('

我想使用Perl来分割路径

funit/pipe/str/str32/gt/split
最多


使用正则表达式。

看起来您只需要父目录的路径;是这样吗?我不会称之为“分裂”道路

对使用正则表达式模式的限制是真正的限制,还是您认为这是最好的方法

下面是一个程序,它使用
Path::Tiny
来执行您的请求

use strict;
use warnings 'all';
use feature 'say';

use Path::Tiny;

my $path = Path::Tiny->new('funit/pipe/str/str32/gt/split');

say $path;
say $path->parent;
输出
欢迎来到StackOverflow。请参加,学习提出好问题stackoverflow.com/help/how-to-ask,做一个回答。MCVE应包括各种样本输入(说明所有方面)和所需输出。请展示您自己的编码尝试。您尝试了什么?你有什么问题?请向我们展示您的代码(如果您没有任何代码,那么堆栈溢出可能是问这个问题的错误位置)。这看起来不像regex,我确实有相同的问题,但是我需要使用它来配置nginx
use strict;
use warnings 'all';
use feature 'say';

use Path::Tiny;

my $path = Path::Tiny->new('funit/pipe/str/str32/gt/split');

say $path;
say $path->parent;
funit/pipe/str/str32/gt/split
funit/pipe/str/str32/gt