need help to look for a word
-
so i need to look for a word, lets say the word is interface, it would find it but also it won’t.
in the big garble of words in the text file it could look like the below:
192.168.1.1;interface
192.168.1.3interfacePresently it would find and highlight the word interface from 192.168.1.1;interface but not from 192.168.1.3interface, without the semi colon.
What Im trying to get help with is, find any interface name without semi colon in front
-
@Alex-Yuan-CA said in need help to look for a word:
find and highlight the word interface from 192.168.1.1;interface but not from 192.168.1.3interface,
You probably have this setting checkmarked:
Uncheckmark it.
The software sometimes even gives you instruction about this:
-
@Alex-Yuan-CA in case you are trying to simply use in-document highlighting instead of the Find window, there are similar options in the Highlighting section of the Preferences window (Settings > Preferences…):
-
In case you are trying to do any other possible text manipulation, searching, highlighting, etc, etc, or anything you can possibly think of doing to your text, please consult the Notepad++ online user manual, because your answer is probably found there.
-
@Alex-Yuan-CA If you open the Find/Replace pop up and select the Regular expression mode at the bottom and type
;interface(*SKIP)(*FAIL)|;interface
you will find all of them (skipping the preceding;
) upon hitting the Find button. An explanation for this method of regular expression (RegEx) can be found at https://community.notepad-plus-plus.org/topic/26812/generic-regex-how-to-use-the-couple-of-backtracking-control-verbs-skip-fail-or-skip-f-in-regexes -
@Alex-Yuan-CA said:
What Im trying to get help with is, find any interface name without semi colon in front
@dr-ramaanand said:
;interface(*SKIP)(*FAIL)|;interface
@dr-ramaanand Does this meet the need?
-
@Alan-Kilborn Sorry, that should be
;interface(*SKIP)(*FAIL)|interface
on Notepad++. I thought I had deleted the last; (semi-colon)
but while pasting it above, I pasted it with it -
@dr-ramaanand said in need help to look for a word:
@Alan-Kilborn Yes, please check it out on Notepad++
It didn’t work. It found 0 matches, when it should have found one. Please be careful when giving advice, that it at least does what you claim it does.
This is not a situation where you need the complications of skip/fail. As @Alan-Kilborn showed, it can be done with a simple non-regex search; if it can be done simply, trying to apply the complicated formula is the wrong thing to do. Even with regex, it would be easier in this case to use a fixed
positivenegative lookbehind (since the semicolon is always one character, you don’t need to worry about variable size, so the Boost regex engine can handle th lookbehind just fine), rather than trying to apply the advanced skip/fail.
To future readers: the post I quoted got changed while I was replying to it. Sorry that it makes it look like I was making up quotes. Even after @dr-ramaanand’s change to his post, my claim that this is not a situation where skip/fail is needed still stands.
-
@PeterJones If he or anyone else wants to use a negative look behind assertion, he can use the method explained at https://npp-user-manual.org/docs/searching/#assertions in which case, he should use the regular expression
(?<!;)interface
in the Find field, that is, he should select the regular expression mode in the Find/Replace pop up and use(?<!;)interface
in the Find field before he hits the Find/Replace button - it will help findinterface
if it is not preceded by a; (semi-colon)
. I gave him theSKIP/FAIL
method of finding that word if it was not preceded by a semi-colon simply because it is easier - please see the explanation at https://community.notepad-plus-plus.org/topic/26812/generic-regex-how-to-use-the-couple-of-backtracking-control-verbs-skip-fail-or-skip-f-in-regexes (if one clicks this link, one can see that it is easier especially because it shows the part skipped and the part matched) -
@dr-ramaanand said in need help to look for a word:
simply because it is easier
That’s apparently a matter of opinion. To me, negative lookbehind, where it’s telling you “look behind the current position, and make sure it’s not XYZ” is a lot easier to read/understand than “match something, then say, wait no, I don’t actually want to match that, let’s fail this whole path and move on to the alternation”. (And, from what I can tell, that’s not really a good explanation of skip+fail, because it takes our regex guru pages of text to explain it, whereas I can successfully convey the meaning of a negative lookbehind in one sentence.)
Since your first version of the skip+fail post was wrong, and you couldn’t tell this immediately, even after it was pointed out to you that it was wrong, I am not convinced that it’s truly as “simple” – even for you – as you are implying.
I am going to stick with recommending solutions that i could explain if necessary; I will only personally link to the skip+fail formula if I know of no other way to do something (and I wouldn’t tell anyone it’s “simple”)
But if it truly makes more sense to you than a negative lookbehind, that’s great for you; everyone is different.