how is npp's regex different from https://regex101.com/ regex?
-
where can I read to under the differences in nppâs regex and https://regex101.com/ regex?
I test at that site and get my regex working there, then I come to my desktop and run that regex in npp, and it doesnât work. Though changes to be done are small, still why should there be anything different in regex at different places.
If any particular of the 4 options of type of regex is to be ticked at the site to make the site give regex as copatible with npp, please tell me.
Thanks.
-
PCRE is the most-compatible selection at regex101. Didnât I mention to you before that there are different flavors of regex and that Notepad++'s is PCRE-like, but is specifically the Boost implementation?
There are regex tools out there which will help you create/test regular expressions that will be 100% compatible with Notepad++, but I know of none that are free if that is a factor for you. I guess it depends how much time you waste with this and how valuable your time is.
There is a FAQ entry which discusses documentation for Notepad++'s regexes, have you looked at that?
-
@V-S-Rawat
may I ask you what your goal is?
Do you use this site just to get a description about what your regex will be doing
and then to use this regex it with the find/replace dialog?
Or are you planning to use it with python scripts?If the latter is the case, one of the recent version of pythonscript plugin has
a regextester script which I would recommend as it is using the re⌠methods.In generel, as weâve found out here, even the same boost:regex engine might have different implementations.
@Alan-Kilborn
regextester might count as a free alternative, doesnât it? :-) -
@Eko-palypse said:
regextester might count as a free alternative
Might be the best bet. I havenât liked it all that much, though.
-
the main difference, which might be relevant to you, as iâve seen in the past, is the
/
.in pcre/php, a regex is usually started and ended with a â/â as delimiter, followed by modifiers m, s, i, etc.
(you can find an explanation of pcre modifiers >>> here <<< )
example of a pcre regex string:/^(.*?)search_string(.*?)$/msi
therefore all
/
used in your regex search have to be escaped as\/
if you use it in pcrein notepad++ your input field is just the pure regex that would be inside the two
/
of pcre, and modifiers are usually set separately, like checking ofmatch case
instead of leaving out thei
in the pcre regex string.as you just input the pure regex, without delimiters or modifiers in the npp search field, itâs best to watch out for all occurrences of an escaped
\/
and replace them with an unescaped/
so a pcre search string like:
/^(.*?)my\/path\/to\/my.exe/msi
would have to be adapted for notepad++ like this:
^(.*?)my/path/to/my.exe
-
FYI:
- one has to distinguish two uses of âPCREâ:
a. the name of a regular expression engine library (its successor is called PCRE2);
b. indicating a regular expression engine library is PERL Compatble; - the official release of Notepad++ is compiled including the Boost Regex library which can be (and is) configured as a PERL Compatible Regular Expression (PCRE) engine;
- Notepad++ compiled without Boost uses the RE engine as included with Scintilla which is ECMAScript (JavaScript) compatible;
- one has to distinguish two uses of âPCREâ:
-
It may be worth noting that the
/.../xyz
style that regex101 uses has an analog in Notepad++ regex syntax that looks like this:(?xyz-uvw)....
where features xyz would be turned ON as shown and features uvw would be turned OFF. Note that xyz and uvw arenât real features, just trying to demo the syntax. This usage in Notepad++ usually leads off the regex (athough it can happen in the middle to affect only what comes after) and overrides the settings of any of the UI checkboxes. Useful features for N++ are:i
or-i
: ignore case or match case, respectively
s
or-s
: single line mode or not, respectively (allows.
to match a line-ending character, or not)
m
or-m
: multiple line mode or not, respectively (not sure the usefulness of this, TBH, maybe in the link above?)
x
: ignore whitespace in regex for a more pleasing visual experience -
It may be worth noting âŚ
maybe, but maybe not for @V-S-Rawat.
the last time i gave him an extensive answer, about how to test notepad++ commits, he politely slowed me down a bit and said, that it was too much information for him.
so i stick to the minimised information that might be of relevance for him, always knowing that he will ask if he needs anything more.
i quote:
@V-S-Rawat said: (By any chance, are you believing me to be a computer wizard? Wrong assumption, dear sir :-) )
-
Well, we are also posting for others that might see and learn something, not just the OP. :)
-
i just try to avoid getting reprehended again by trying to learn how to correctly respond to users i know đ
note: if you want it to address it to all others, you can add âand allâ as a suffix to the @Meta-Chuh tag, or, if it is originally not meant for me, donât use my tag at all.
-
@Meta-Chuh (meant for you!):
Sure. If it is in direct reply to something you pointed out, I hit the small
reply
next to your posting. If it is a generic reply, I press the blueReply
button below all postings. I think âand allâ might be a bit redundant, as anybody interested can read any reply without being directly invited to. :) -
@Alan-Kilborn Yes, I was looking for some free site which gives regex testing totally compatible with npp. :-(
-
@Eko-palypse I am newbie to regex so I face problem in formulating them.
npp doesnât provide any help in developing a regex as it doesnât tell what is wrong where.
I wanted some site like the one mentioned that would give regex that would run 100% âas suchâ in npp.
As that site is also having a âpythonâ flavor of regex mentioned, I think pythonscript pluginâs regex would also be different from regex that would run from nppâs default find replace.
-
@Meta-Chuh said:
the main difference, which might be relevant to you, as iâve seen in the past, is the
/
.in pcre/php, a regex is usually started and ended with a â/â as delimiter, followed by modifiers m, s, i, etc.
(you can find an explanation of pcre modifiers >>> here <<< )
example of a pcre regex string:/^(.*?)search_string(.*?)$/msi
therefore all
/
used in your regex search have to be escaped as\/
if you use it in pcrein notepad++ your input field is just the pure regex that would be inside the two
/
of pcre, and modifiers are usually set separately, like checking ofmatch case
instead of leaving out thei
in the pcre regex string.as you just input the pure regex, without delimiters or modifiers in the npp search field, itâs best to watch out for all occurrences of an escaped
\/
and replace them with an unescaped/
so a pcre search string like:
/^(.*?)my\/path\/to\/my.exe/msi
would have to be adapted for notepad++ like this:
^(.*?)my/path/to/my.exe
Yes, that was the main difference I had observed. Clarifying that was indeed helpful.
Thanks.
-
@Meta-Chuh said:
the last time i gave him an extensive answer, about how to test notepad++ commits, he politely slowed me down a bit and said, that it was too much information for him.
:-) Sorry for that. I am a newbie at regex, and my growing age is blunting my quick learning. Smaller bites help me. :-)
Thanks for considerations.
-
That brings me to an idea.
I assume that these regex libraries are available ready to be compiled with apps and are for free.
In that case, can boost regex library be removed from npp and can npp be compiled with other such libraries?
Can a user do it if npp code is available?
Or can I ask for this a new feature in regex that npp is compiled will âALLâ libraries of regex, and find/ replace window gets a new option of "what type of regex (âPCRE/ Pyton/ Java/âŚ)?â
That will probably make npp the only editor that has option to use all types of regex at the tick of a check box.
What would be pros and cons of that?
-
Also, as @Eko-palypse shared above, pythonscript provides its own regex tester, which is different from nppâs default boost regex library,
so, can flavors of all type of regex libraries be supplied as a plug-in (or one for one plug-in) to be used with npp?
I canât do that, maybe a hint for plug-in developers.
-
btw: @MAPJe71 recently posted a free offline regex tester tool.
@MAPJe71 wrote: Additional Regex Tester tool (offline): RegEx Tester
maybe this tool can be of interest for you too.
-
@Meta-Chuh promptly downloaded that. shall test when next requirement comes up.
maybe, npp developers can crack an arrangement with @MAPJe71 to bundle the tester zipfile with npp installer.
-
@V-S-Rawat said:
Also, as @Eko-palypse shared above, pythonscript provides its own regex tester, which is different from nppâs default boost regex library,
True, but the closest you can get at the moment - as far as I know.
One question you havenât answered, or I have over read, is what you are doing with the regex at the end.
If you use the find replace dialog then non of the solution will 100% fit and the closest might be
the RegexTester from PythonScript plugin.
If you want to use the regex within a PythonScript plugin then RegexTester matches 100% .The idea of having all regex engines in one product is a nice idea but doesnât guarantee it is always
like it is in npp. Just a note, C++ (14/17 ??) has now its own regex engine as well.