-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDoubleQuotedString.regex.ps1
More file actions
38 lines (33 loc) · 997 Bytes
/
DoubleQuotedString.regex.ps1
File metadata and controls
38 lines (33 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<#
.Synopsis
Matches double-quoted strings.
.Description
Matches a double quoted string, with an optional escape sequence (defaulting to backtick or backslash).
#>
param(
# The escape character
[string]
$Escape
)
if ($inputObject) {
if ($inputObject -is [IO.FileInfo]) {
$escape =
if ('.h', '.cpp', '.c', '.cs', '.js', '.java','.json', '.htm', '.html', '.xml', '.pswt' -contains $inputObject.Extension) {
'\'
} elseif ('.ps1', '.psm1', '.psd1' -contains $inputObject.Extension) {
'`'
}
if (-not $Escape) { return }
}
if ($inputObject -is [Management.Automation.CommandInfo] -or
$inputObject -is [ScriptBlock]) {
$Escape = '`'
}
if (-not $Escape) { return }
}
if ($Escape) {
$escape = $escape -replace '[\p{P}\p{S}]', '\$0'
"(?<!\@)`"(?:.|\s)*?(?<!$escape)`""
} else {
'(?<!\@)"(?:.|\s)*?(?<!(`|\\))"'
}