All Questions
18 questions
-2
votes
1
answer
97
views
Powershell regex replace : string is unchanged
I'm trying to regex replace some groups of charactes in powershell using the following pattern:
/^(thedir[ ]=[ ]")(.)(:[/\])([a-zA-Z0-9])([/\]?.)$/gm
by using this instruction:
$fileContent = Get-...
1
vote
1
answer
71
views
Multiline regex from single long string
This is in Powershell 7.x, but I believe it is a general regex question.
I have the headers from an email in one long string, and would like to capture them with the Powershell split function using a ...
0
votes
0
answers
30
views
Powershell | Select-String multiple lines regex pattern filters nothing [duplicate]
The situation
I have a string like this:
some-text <!--
<div class="">
</div> --> some-other-text
From which I want to get only what's commented, so like this:
&...
0
votes
2
answers
71
views
PowerShell/C# regex multiline replace returns wrong line ending
I have a textfile with CRFL line endings, I read the whole file with
$c = Get-Content -Raw file.txt
the file contains e.g.
exec Add a, b, c
exec Rem e, f, g
I try to replace it with my regex
$...
2
votes
2
answers
178
views
PowerShell: Match Expression Against Text File Using String-Select
I'm trying to use Select-String in PowerShell to extract lines from a text document containing entries from a change log. I've included a sample, below.
The PS command Select-String "REAPER.*(19|...
0
votes
1
answer
50
views
Parsing A Log Item Into Custom Object
I am trying to parse log line items into a custom powershell object to add to a collection I can iterate, however I am having trouble figuring out how to find the specific data within the log item. ...
3
votes
1
answer
1k
views
Multiline regex match in PowerShell with or without lookahead
I'm trying to format markdown file so that there is one empty line after the headings, the file is UTF8 encoded with CRLF line breaks, here is example file:
## DESCRIPTION
description entry...
## ...
2
votes
1
answer
899
views
Powershell multiline pattern matching and picking those lines
I am trying to pick the lines from a log file based on multi-line match. How do we achieve this with Powershell?
LogFile:
Date: 2020-05-06 2:30:33 PM
Name: ABC.txt
{text}
{text}
{text}
Date: ...
0
votes
2
answers
201
views
How do I extract content from a textfile with multiline regex in powershell?
I have a file called list1.txt which contains
192.168.1.1
|root:pass\x0Droot\x0Dvizxv\x0Dadmin\x0D888888\x0Dxmhdipc\x0Ddefault\x0Djuantech\x0D123456\x0D54321\x0Dsupport\x0Droot/\x0Dpassword\x0D12345\...
0
votes
0
answers
120
views
Replace a Multiline String using Regex in PowerShell [duplicate]
I am trying to achieve this but it is working in Notepad++ but not in PowerShell+regex
File: 1.txt
1
2
3
4
PS:
(Get-Content E:\1.txt).replace("(?ms)1((?:.*\r?\n?)*)4", "success") | Set-Content E:\2....
2
votes
1
answer
293
views
Extracting a table from a text file using PowerShell
I have a table that I want to extract from a batch of text file. The problem is that the table does not begin at the same line in the every text file. Also, the presentation, format, and reuse of ...
1
vote
0
answers
244
views
How to name capture with multi-line regex from multi-line string
I know how to use named capture on an array of lines but... how do I use named capture on multi-line string?
$herestring = @"
Foo
Bar
Foo
Manchu
"@
$pattern = [regex]'(?s)(?<Foo>...
0
votes
1
answer
366
views
Unable to match a multiline regex with Powershell (but it does work in C#)
Given:
PS D:\tmp> cat .\1.txt
<abc xyz="1"
def="xx">
xaxa
</abc>
<abc xyz="a">
PS D:\tmp>
What I was trying:
PS D:\tmp> cat .\1.txt | sls '(?m:)<abc[^>]+>'...
0
votes
2
answers
635
views
powershell multiline regex block
I'm literally pulling hairs out in frustration on trying to use multiline regex, I've very little experience with Powershell, and while the examples I've tried work, as soon as I start to adjust them ...
3
votes
4
answers
836
views
Capture multiline, multi-group to Powershell variables
Ideally, I would like to create an object from ipconfig that allows us to drilldown to each adapter's attributes like this: $ip.$lan.$mac for the lan adapter's mac address.
To start, I would like to ...