0

I am trying to create a find command to find the files that git create when there is a conflicting rebase/merge.

.//Tools/tri_tri_intersect.h
.//Tools/tri_tri_intersect.cpp
.//Collisions/PBD/FiltersUtils_BACKUP_450361.cpp
.//Collisions/PBD/FiltersUtils_BASE_450361.cpp
.//Collisions/PBD/FiltersUtils_LOCAL_450361.cpp
.//Collisions/PBD/FiltersUtils_REMOTE_450361.cpp

From this list of files, I want a find command to select the last 4, the ones with BACKUP, LOCAL, REMOTE, BASE.

I have tried this find . -type f -regex '.+_((BACKUP)|(BASE)|(LOCAL)|(REMOTE))_.*' but doesn't work.

What would be the correct regex?

αғsнιη
  • 40,939
  • 15
  • 71
  • 114
jjcasmar
  • 263
  • 2
  • 10
  • Add `-regextype egrep` to your command. – nobody Feb 02 '23 at 20:04
  • That worked. Can you explain the difference between adding it and not adding it? – jjcasmar Feb 02 '23 at 21:26
  • 1
    At least for the GNU implementation, the default regextype is `emacs` - which supports an ERE-style `+` quantifier, but grouping and alternation must be escaped like POSIX BRE: `'.+_\(BACKUP\|BASE\|LOCAL\|REMOTE\)_.*'`. See also [Confusion with Linux find regex](https://unix.stackexchange.com/questions/560896/confusion-with-linux-find-regex) – steeldriver Feb 02 '23 at 21:33
  • ... but personally I'd probably avoid the confusion by sticking with standard glob patterns: `find . -type f \( -name '*_BACKUP_*' -o -name '*_BASE_*' -o -name '*_LOCAL_*' -o -name '*_REMOTE_*' \)` – steeldriver Feb 02 '23 at 22:06
  • 1
    So there are some webpages that allow to test regex patterns. https://regexr.com/ or https://regex101.com/. I like them because they also teach what is each part of the regex doing, useful for debug it. But how can I know is they are emac, ERE, Posix BRE? – jjcasmar Feb 02 '23 at 22:40
  • @jjcasmar it's complicated - see for example [Why does my regular expression work in X but not in Y?](https://unix.stackexchange.com/questions/119905/why-does-my-regular-expression-work-in-x-but-not-in-y) – steeldriver Feb 02 '23 at 23:33

0 Answers0