For example if I have a file with the following 3 lines of text in it;
LINE1: DESC_
LINE2: DESC_,
LINE3: DESC_
The strings ‘_ ‘ & ‘_,’ can appear anywhere in the line for LINE1 & LINE2 but only at the end of the line for LINE3.
Using a regex expression of ‘_[s,]’ I can easily match LINE1 and LINE2 but when I try to use an optional anchor like _[s,$] it does not fine the match in LINE3.
Suggestions?
Writing this in Windows PowerShell using the -match operator.
Test util:
target_strings.txt
#SAMPLE TARGET STRINGS
DESC_
DESC_,
DESC_
Note: EOL immediately following the last line’s text
Clear-Host
$LINES = Get-Content -Path C:datadeployment_toolsTARGET_STRINGS.txt
foreach ($LINE in $LINES)
{
if ($LINE -match '_ ') {write-host "$LINE matches regex '_ ' "}
if ($LINE -match '_,') {write-host "$LINE matches regex '_,' "}
if ($LINE -match '_$') {write-host "$LINE matches regex '_$' "}
if ($LINE -match '_[ ,$]') {write-host "$LINE matches regex '_[ ,$]' "}
}
Looking for one regex statement that matches all 3 conditions.
2