首页 > 解决方案 > git bash中的正则表达式要转义哪些字符

问题描述

正则表达式:

(壮举|修复|hf)/\d*/.*

适用于以下文本:

Merge pull request #32 in TAS/tashtit from feat/140844/fix-sonar-properties to develop feat/140844/ fixing problems found by sonar Merge pull request #31 in TAS/tashtit from feat/140844/fix-sonar-properties to develop feat/140844/ fix sonar properties and git ignore Merge pull request #30 in TAS/tashtit from feat/141316/jndi-junits to develop Merge pull request #28 in TAS/tashtit from feat/142391/log-event-fix to develop feat/142391/ fix jenkins Merge branch 'develop' into feat/141316/jndi-junits Merge pull request #27 in TAS/tashtit from feat/142391/log-event-fix to develop feat/142391/ Merge branch 'develop' of http://pa2vmp56.blmain.prod:7990/scm/tas/tashtit into feat/142391/log-event-fix feat/142391/ fix jenkins Merge branch 'feat/141466/Check-that-refactored-code-works-with-J2EE' into feat/141316/jndi-junits Merge pull request #26 in TAS/tashtit from feat/141466/Check-that-refactored-code-works-with-J2EE to develop feat/141466/ Merge branch 'develop' of ssh://pa2vmp56.blmain.prod:7999/tas/tashtit into feat/141466/Check-that-refactored-code-works-with-J2EE feat/141466/ fixing events Merge pull request #25 in TAS/tashtit from feat/141466/Check-that-refactored-code-works-with-J2EE to develop feat/141466/ fixing application port Merge branch 'develop' into feat/141316/jndi-junits Merge branch 'develop' into feat/141316/jndi-junits Merge branch 'develop' into feat/141316/jndi-junits

问题是在 git bash 中编写命令时,我收到有关转义的错误。这是命令:

git -C /c/workspace/Tashtit-Spring-Dev-Build log tashtit.spring_build_1902.01.1911211325..tashtit.spring_build_1902.01.1911281247 --grep=(?:feat|fix|hf)\/\d*\/.* --all-match --pretty=%s > /c/workspace/Tashtit-Spring-Dev-Build/log.log  

因此,我尝试转义特殊字符,如下所示:

git -C /c/workspace/Tashtit-Spring-Dev-Build log tashtit.spring_build_1902.01.1911211325..tashtit.spring_build_1902.01.1911281247 --grep='\(?:feat|fix|hf\)\/\d*\/.*' --all-match --pretty=%s > /c/workspace/Tashtit-Spring-Dev-Build/log.log

结果是空的,我错过了什么?

标签: regexgitescapinggit-bash

解决方案


推荐阅读