All Questions
Tagged with powershell regex
2,320 questions
0
votes
0
answers
27
views
regex match exact string or string with specific next character [duplicate]
I want to test a string for something like 'UNIT_40' or 'UNIT_40\' but want to exclude strings like UNIT_4080. I can search for 'UNIT_40$|UNIT_40\\' but is there a less redundant way to craft the ...
-1
votes
1
answer
43
views
Trouble with Regular Expression matching in PowerShell when lines contain "$" sign
I am trying to perform search and replace using RegExs in PowerShell like the following:
Julie found "NoMoney" in "Easter Island" => Julie("Easter Island") = "...
1
vote
1
answer
64
views
SSIS Job using PowerShell get-content -replace removing too much
I have an SSIS Package, in the control flow, I have FOR EACH FILE loop which takes each file, a CSV with " text qualifiers, and attempts to apply some changes using the EXECUTE PROCESS TASK.
What ...
2
votes
1
answer
61
views
Regex Powershell: find a string, then replace nth occurence of another string
I have 200 files with lines of text, that could look like any of these paterns:
{hello} "this is an example" {{ config(alias="customertable") }}
{{hello}} "this is an example&...
3
votes
3
answers
84
views
powershell Regex - match only the strings that starts with one occurrence of special chars
I've a file that contains:
# cat
######## foo
### bar
#################### fish
# dog
##### test
with 'Get-Content file.txt | Select-String -Pattern "^#"' I match all those lines...
How to ...
3
votes
2
answers
191
views
PowerShell code returning correct value. However, looking to enhance program by capturing the ID tag listed above the desired value
Good evening. Stack Overflow and Powershell and RegEx novice here.
The below Powershell code is returning the correct value as well as a little pre context and post context. However, I am looking to ...
2
votes
1
answer
62
views
Regex to match quoted and non-quoted text, and not any part matches
Have given up on figuring this out on my own.
Sample string to work the regex on:
"this","is","a","test"
The below regex works fine for double quoted (once) ...
2
votes
2
answers
90
views
PowerShell multiline regex is matching on regex101.com AND regexr.com, but not in Powershell code
This regex: (?is)[\s\S]*?\[General\][\s\S]*?SystemMustBeRebooted=(\d)[\s\S]*?\[Install Execution\][\s\S]*?SilentInstall=""(.*?)"".* doesn't match the below cut down part of the ...
-1
votes
2
answers
95
views
For loop PowerShell command within a batch file removes apostrophe
I have a problem with a PowerShell command within a batch file for loop.
The script retrieves forenames and surnames from either side of a period in the local part of email addresses.
For example joe ...
0
votes
3
answers
78
views
Can't split string with regex
I want to split two sentences with 'apple' and 'apples' simultaneously. I try to use a regular expression 'apple*' or 'apple?'. But it doesn't work. I see the 's' in the second part of the second ...
1
vote
2
answers
68
views
Split string by a word, unless
I want to split the sentences with "for", unless "all for" occurs in the sentence. It almost works, but for some reason one letter "s" is missing. What's wrong?
$arr = '...
0
votes
2
answers
101
views
Regex in powershell command
The command below matches all shares (C$ , Admin$ , test55). I need to omit any shares that end with $. Please help.
net view \\computername /all 2>&1 | select-object -Skip 1 | ?{$_ -match '...
3
votes
3
answers
90
views
Powershell regex for string in git commit subject
I am trying perform a git log using this git log "Version_10.1.18.1...Version_10.1.18" --format="%s" for just the` subject in the commit messages like these
Merged PR 17055: 94683: ...
1
vote
2
answers
81
views
why does string -replace operator to duplicate backslashes (as neeeded for wmic input) result in 4 backslashes
One might need to replace each backslash in a string, say a file path, with double-backslash. Eg, wmic requires this (eg: https://stackoverflow.com/a/50878476/4582204).
So one might try this code
'foo\...
0
votes
0
answers
85
views
Negative lookahead not working as intended
I would like to create a regex, that matches along the following criteria and I am using the Select-String function of PowerShell. I have this query,and I want to get all parameter variations(so the ...