获取与常规的前pressions分离器之间的东西 [英] Get something between separators with regular expressions

查看:100
本文介绍了获取与常规的前pressions分离器之间的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个寄存器是这样的提取的中间值:

I am trying to extract the middle value from a register that is something like this:

NAME=PATH=USER=DATE

我需要得到的路径部分和所有我想出了是这样的:

I need to get the path part and all I came up with is this:

=[^=]*=

问题是,它包括=在开始和结束时。我怎么能不包括他们?

the problem is that it includes the = at the beginning and at the end. How could i not include them?

此外,它的UNIX命令我应该使用解压呢?我在想SED,但我通常用它来替换字符串没有得到他们。用grep可能?

Also, which unix command should I use to extract it? I was thinking sed, but I usually use it to replace strings not to get them. grep maybe?

我bash编程是新...

I am new in bash programming...

有没有在那里我可以学到一些正则表达式的任何地方吗?因为我觉得我需要真正知道如何与他们合作。

Is there any place where I can learn some regex? because I think I will need to really know how to work with them.

推荐答案

使用捕获组:

if [[ $str =~ =([^=]+)= ]]
then
    echo "Part between = and = is ${BASH_REMATCH[1]}."
fi

这篇关于获取与常规的前pressions分离器之间的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆