0

I am newbie in writing scripts in powershell, and even more in regular expressions, please help with the implementation.

example:

PS > .\test.ps1 "A Balrog is a powerful fictional monster in Middle-earth."
return: Middle-earth

or

PS >.\test.ps1 "The symbol underscore, also called low_line or low dash."
return: low_line

of course I tried to find a solution for this problem, here is my solution:

#$data = $args[0]

$p = '\w*[-_]\w*'

Select-String -Path .\content.txt -Pattern $p | % {$_ -match $p; $matches.Value}

Write-Output $matches

=========================================== Update: Solution found

  • actually regex will be like this: '\w*[-_]\w*', this greate [link](https://regex101.com/r/AuWxVu/16/) come with help –  Jan 18 '21 at 09:35

1 Answers1

0
$data = $args[0]

$pattern = '\w*[-_]\w*'

$matches = [regex]::Matches($data, $pattern).Value

Write-Output $matches