### The regex in `Excluded Files` doesn't work as expected

Things I have tried

Hello everybody, I’m new to obsidian. It is really a fantastic knowledge base app. Since I want to use obsidian as my knowledge base, it will handle a lot of files and folders. So I want filter out some misc files when do search or something.
For example, ignore all files under a certain pattern folder like folders preceded by an underscore _*, _folder_ignored, …
I noticed the feature Options -> Files & Links -> Excluded Files.

What I’m trying to do

I have search in the forum with query excluded files regex. I have found this, Config to ignore/hide select files and folders - #131 by ryanwwest. I realize it may be a fresh feature in a recent version.

The I have done some test try to find out how the regex in Excluded Files work.

Environment

  • mac os 10.15.7
  • obsidian version 0.15.9

I build a folder to test. The structure as follows:
file structure:

test regex/
	_FilePreUnderscore
	File_InnerUnderscore
	FileNoneUnderscore
	_precedingUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	NoneUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	Underscore_inner/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore

I tried several regex and list the corresponding results. The queries are all Underscore in the cases.

case 1
regex:
/__*/
results:

test regex
	FileNoneUnderscore
	NoneUnderscore/
		FileNoneUnderscore

I suppose the regex will filter out files or folders in which there is an underscore.

results should be:

test regex/
	_FilePreUnderscore
	File_InnerUnderscore
	FileNoneUnderscore
	_precedingUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	NoneUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	Underscore_inner/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore

which filter out the files preceded by a double underscore.

case 2
regex:
/_*/
results:

No matches found.

I suppose the regex will filter out all the files and folders which is actually *.

results should be:

test regex/
	File_InnerUnderscore
	FileNoneUnderscore
	_precedingUnderscore/
		File_InnerUnderscore
		FileNoneUnderscore
	NoneUnderscore/
		File_InnerUnderscore
		FileNoneUnderscore
	Underscore_inner/
		File_InnerUnderscore
		FileNoneUnderscore

which filter out the files preceded by an underscore.

case 3
regex:
FileNoneUnderscore
results:

test regex/
	_FilePreUnderscore
	File_InnerUnderscore
	FileNoneUnderscore
	_precedingUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	NoneUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	Underscore_inner/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore

results should be:

test regex/
	_FilePreUnderscore
	File_InnerUnderscore
	_precedingUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
	NoneUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
	Underscore_inner/
		_FilePreUnderscore
		File_InnerUnderscore

which filter out the file FileNoneUnderscore no matter where it is. (a .gitignore style)

case 4
regex:
/**/_precedingUnderscore//
results:

test regex/
	_FilePreUnderscore
	File_InnerUnderscore
	FileNoneUnderscore
	_precedingUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	NoneUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	Underscore_inner/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore

results should be

test regex/
	_FilePreUnderscore
	File_InnerUnderscore
	FileNoneUnderscore
	NoneUnderscore/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore
	Underscore_inner/
		_FilePreUnderscore
		File_InnerUnderscore
		FileNoneUnderscore

which filter out all the file under the _precedingUnderscore (a python glob style, glob.glob("**/_precedingUnderscore/").

What the rule of regex in Excluded FIles? Any help will be appreciated.

What the rule of regex in Excluded FIles?

I think it’s normal JavaScript-RegEx.

case 1

/__*/ is the same as /_+/
the quantifier “*” says zero or more = {0,}
the quantifier “+” says one or more = {1,}

case 2
/_*/ this will match everything because you say match all with zero or more underscores

case 3
If you want to exclude some chars you can use a negative charset, [^_]
^ = inside at the beginning of a charset = metachar for a negative charset

case 4
Didn’t understand it.

If you just want to match underscores at the beginning of a string you have to set an anchor, e.g. /^_+/
^ = anchor for the beginning of a string

Thanks! I had limited my mind to .gitignore style.
The pattern /\/_[^/]*\// works as expected which filter out all the files and folders under a folder preceded by an underscore.