1
我有這個文本https://bitbucket.com/user/repo.git
,我想打印repo
,內容爲/
和.git
,不包括分隔符。我有這個:在grep中打印匹配正則表達式組
echo https://bitbucket.com/user/repo.git | grep -E -o '\/(.*?)\.git'
但它打印/repo.git
。我如何才能打印repo
?
我有這個文本https://bitbucket.com/user/repo.git
,我想打印repo
,內容爲/
和.git
,不包括分隔符。我有這個:在grep中打印匹配正則表達式組
echo https://bitbucket.com/user/repo.git | grep -E -o '\/(.*?)\.git'
但它打印/repo.git
。我如何才能打印repo
?
與-P
選項使用[^/]+(?=\.git$)
模式:
echo https://bitbucket.com/user/repo.git | grep -P -o '[^/]+(?=\.git$)'
的[^/]+(?=\.git$)
模式匹配比/
其他1+字符被字符串的結束,隨後用.git
。
您可以使用sed
做
echo https://bitbucket.com/user/repo.git | sed -e 's/^.\*\\/\\(.\*\\).git$/\1/g'
謝謝,它的工作原理。 –