Skip to content

problem with snippets regex #40570

@asaadmohammed74

Description

@asaadmohammed74

i want to make a snippet that give the path of current open file relative to ${workspaceRoot}/src so i made this

{
"get path": {
		"prefix": "gp",
		"body": [
			"${TM_DIRECTORY/.*src(.*)/$1/}",
		]
	}
}

this work's but for files like /home/username/MyProject/src/dir1/dir2//foo.cc this gives /dir1/dir2 so i changed it to this

"get path": {
		"prefix": "gp",
		"body": [
			"${TM_DIRECTORY/.*src[\/](.*)/$1/}",
		]
	}
}

so now i expect it to show dir1/dir2 instead it expands to this ${TM_DIRECTORY/.*src[/](.*)//} and this happen with any regex that contain \/

same with this "${TM_DIRECTORY/[\/](.*)/$1/}", expands to ${TM_DIRECTORY/[/](.*)//}
and for some reason this ${TM_DIRECTORY/.*src[\\/](.*)/$1/} works and expands to dir1/dir2
but on https://regex101.com this is invalid

Metadata

Metadata

Assignees

Labels

*questionIssue represents a question, should be posted to StackOverflow (VS Code)snippets

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions