0

I use the following line in powershell, which finds what I am looking for.

Select-String -Path *.txt -Pattern '(.*)pov\"(.*)Fred(.*)\"$'

but I cannot get the find command in notepad++ to find anything.
Wrap around selected , Regular Expression Selected , Newline not selected
Is there some basic difference between the way these two systems use regex.

line example is:- pov" example text Fred "

5
  • 4
    I can't reproduce this, it works for me. Did you remove the 's from the pattern?
    – DavidPostill
    Commented Feb 16, 2021 at 18:21
  • the regex engine in notepad++ is PCRE, the one in PoSh is the dotnet engine with a few convenience tweaks [default to case insensitive, for instance].
    – Lee_Dailey
    Commented Feb 16, 2021 at 21:09
  • Hey you forgot to accept my answer(click that tick icon):) Commented Feb 17, 2021 at 3:33
  • @Lee_Dailey: Just a remark, regex engine used by Notepad++ is Boost, not PCRE. Nevertheless, that doesn't make a great difference.
    – Toto
    Commented Feb 17, 2021 at 8:40
  • @Toto - thank you! i managed to miss the switch from PCRE to Boost. [blush]
    – Lee_Dailey
    Commented Feb 17, 2021 at 21:43

1 Answer 1

1

I was able to reproduce the problem in Notepad++ 7.9.2 and I instantly solved it.

How did I reproduce it

Use '(.*)pov\"(.*)Fred(.*)\"$' (WITH single quotes), it returns error: Find: Can't find the text "'(.*)pov\"(.*)Fred(.*)\"$'", which is correct.

enter image description here

How did I solve it

Just remove the single quotes and it will correctly find the matches:

enter image description here

Explanation

Regular expressions are treated as strings, in PowerShell texts enclosed in quotes (' and ") are treated as string objects, in most if not all programming languages you need to explicitly use quotes to make a segment of text a string object.

However in Notepad++ everything you type is already treated as strings, so the quotes become literal quotes and part of the string, changing the meaning of the regex so there wouldn't be matches.


Update per comment

I tested it myself and I found that you don't need to use fred (lower-case), Fred (proper-case) works fine, Notepad++ is case-insensitive.

Proof:

enter image description here

2
  • 1
    Yip I was a complete idiot. Was doing this at 2.30 AM.
    – DavidCF
    Commented Feb 17, 2021 at 2:50
  • Just tried it again and it worked OK. Say Fred was replaced by [fred]. I was trying [fred] should I just have used [fred] instead
    – DavidCF
    Commented Feb 17, 2021 at 2:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .