1

I need to search a file for any string that contains the sub-strings "ME" and "SW", in this order, with any character (even non-alphanumerical), before, between and after them.

So far this line works for me:

*select-string -path "..path" -pattern ME*

But, when I try the regex [.]*ME[.]*SW[.]* it returns null.

Also, when using [.]*ME[.]* it works.

2
  • Have you tried quoting the pattern? Commented Jun 11, 2018 at 11:38
  • 2
    [.] will match a literal ., remove the brackets in order for it to match any character Commented Jun 11, 2018 at 11:42

1 Answer 1

4

You should try this....

ME.*SW
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, it worked. Could you explain the difference, I'm a little confused.
The dot symbol is a metacharacter which matches any character excluding line break characters. But if you use it inside brackets it matches only a dot character. For example : AA[.] matches the string "AA.", but not the string "AAA" and AA. matches the string "AA." and also the string "AAA" Hope it helps
The .* before and after ME.*SW are redundant.

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.