0

String being searched

"ran into (something-big) issues do something else bla bla, see log file: "

Pattern should find "(something-big) issues" exact substring, if it exists.

How do I allow parens in the regex pattern

This pattern i've tried fails

\b\(something-big\) issues\b

eg.

$str2 = "ran into (something-big) issues do something else bla bla, see log file: ";


if($str2 -match '\b\(something-big\) issues\b' ) {
    Write-Output "we found it";    
}
else{
    Write-Output "nope";
}   
1
  • this works --- $str2 -match '\(something-big\) issues'. i don't know why yours fails, tho. [blush] Commented Jan 2, 2019 at 16:37

1 Answer 1

3

Your regex pattern correctly returns $false for your input because of:

'\b\(something-big\) issues\b'
# ^ this guy

( is not a word character, and neither is the space that precedes it, so the index of ( is not actually a word-boundary - remove the first \b and it'll work:

$str2 -match '\(something-big\) issues\b'

If you only want to match when a non-word character is present in front of (something-big), use the negated word-character \W (notice W is upper case):

$str2 -match '\W\(something-big\) issues\b'

or use a negative lookbehind:

$str2 -match '(?<!\w)\(something-big\) issues\b'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.