Hi I'm trying to create a script in powershell that finds a string in a file and then modifies it but I'm having issues matching the string I want.
So, I'm trying to make sure that I can find this type of string
|d where d is is any digit, the string must not be in single or double quotes.
SO I'd like to match |1 or |12 or |333
So far this is what I have:
\|[0-9]+
is returning strings with or without single quotes around it, so |1 and also '|5';
\'\|[0-9]\'+
returns only strings with single quotes around it, so matches '|4' but not |3
\\'|'(?:\\'|[^'])*'|(\[0-9]+)
as the first one, it is returning strings with or without single quotes around it, so |1 and also '|5';
\[^']\|[0-9][?']\+
I thought this would say something like exclude ' at the beginning and at the end of the string, but it doesn't work at all
Now, you might have understood that I really don't know much about regex, so I'm trying options in the online regex checker here https://regex101.com/ but it appears to be behaving slightly different than powershell.
Now, what do I have to do to match a string without the quotes? I don't necessarily want the solution, but perhaps some hint would be appreciated :-)
Violet_82
89
Posting Whiz in Training
Recommended Answers
Jump to Post"Windows PowerShell is a programming language from Microsoft that is primarily designed for system administration. Since PowerShell is built on top of the .NET framework, .NET’s excellent regular expression support is also available to PowerShell programmers."
Now, try using .NET's sequence (?!subexpr) and (?<!subexpr).
(?!subexpr) for ex. \w+\b(?![,:;]) will find …
All 3 Replies
rproffitt
2,565
"Nothing to see here."
Moderator
Violet_82
89
Posting Whiz in Training
rproffitt
commented:
The version of powershell might be why. Note: I'm not a historian on this area.
+15
xrjf
213
Posting Whiz
Premium Member
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.