-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSingleQuotedString.regex.ps1
45 lines (37 loc) · 1.12 KB
/
SingleQuotedString.regex.ps1
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
39
40
41
42
43
44
45
<#
.Synopsis
Matches single-quoted strings.
.Description
Matches a single quoted string, with an optional escape sequence (defaulting to two single quotes or a backslash).
#>
param(
# The escape character
[string]
$Escape
)
if ($inputObject -and $inputObject -isnot [string]) {
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) {
if ($escape -eq "'") {
"(?<!\@)'((?:''|[^'])*)'"
} else {
$escape = $escape -replace '[\p{P}\p{S}]', '\$0'
"(?<!\@)'(?:.|\s)*?(?<!$escape)'"
}
} else {
"(?<!\@)'((?:''|\\'|[^'])*)'"
}