-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregex.ps1
46 lines (41 loc) · 1.22 KB
/
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
46
<#
.SYNOPSIS
A custom regex script to replace specific lines in build.ninja files.
#>
# Back up the original file
Copy-Item build.ninja build.ninja.bak -Force
# Read the build.ninja file
$content = Get-Content build.ninja
# Define the replacements
$replacements = @(
@{
Pattern = "^ DEFINES =.*"
Replacement = " TODO: Add your replacement here"
}
@{
Pattern = "^ FLAGS =.*"
Replacement = " TODO: Add your replacement here"
}
@{
Pattern = "^ LANGUAGE_COMPILE_FLAGS =.*"
Replacement = " TODO: Add your replacement here"
}
@{
Pattern = "^ LINK_FLAGS =.*"
Replacement = " TODO: Add your replacement here"
}
)
# Perform the replacements
$newContent = foreach ($line in $content) {
$replaced = $false
foreach ($replacement in $replacements) {
if ($line -match $replacement.Pattern) {
$line = $replacement.Replacement
$replaced = $true
break # Important: Exit inner loop after replacement
}
}
$line # Output the (potentially modified) line
}
# Write the updated content back to the file (or a new file)
$newContent | Out-File -Encoding UTF8 build.ninja -Force