Visual Studio Code Regex contains but not ends with












3















I want to build regex expression in VS Code which returns all the phrases in the whole solution which contain a given string(please keep in mind that it can contain special characters) and not ends with given string e.g.
Contains /webhelp but not ends with /



Matches:



/server/webhelp

blah/webhelp#


Doesn’t match



/server/webhelp/

server#webhelp/


Im not an expert in Regex, I’ve tried to build something like:



(?=/webhelp)(?=.*(?<!/)$)


But it doesn’t work.










share|improve this question























  • You already know that pcre2 option does not enable lookbehinds, why try them? Also, to match some string to highlight or remove it you need to consume the chars, and your regex only contains lookarounds.

    – Wiktor Stribiżew
    Nov 20 '18 at 12:42













  • Try /webhelp(?!.*/$).*$

    – Wiktor Stribiżew
    Nov 20 '18 at 12:44











  • I've just checked this expression and it returns /server/webhelp/

    – GoldenAge
    Nov 20 '18 at 12:49













  • It does not, probably you have spaces after /? Then try /webhelp(?!.*/s*$).*$

    – Wiktor Stribiżew
    Nov 20 '18 at 12:49













  • I've just copied your expression and run the VS Code search engine. It's a pitty that there is no option to link a screenshot in the comment as a proof. I also set the "search.usePCRE2": true in the settings.json file. If this expression should work i don't have any idea why it doesnt, and what is the issue.

    – GoldenAge
    Nov 20 '18 at 12:56
















3















I want to build regex expression in VS Code which returns all the phrases in the whole solution which contain a given string(please keep in mind that it can contain special characters) and not ends with given string e.g.
Contains /webhelp but not ends with /



Matches:



/server/webhelp

blah/webhelp#


Doesn’t match



/server/webhelp/

server#webhelp/


Im not an expert in Regex, I’ve tried to build something like:



(?=/webhelp)(?=.*(?<!/)$)


But it doesn’t work.










share|improve this question























  • You already know that pcre2 option does not enable lookbehinds, why try them? Also, to match some string to highlight or remove it you need to consume the chars, and your regex only contains lookarounds.

    – Wiktor Stribiżew
    Nov 20 '18 at 12:42













  • Try /webhelp(?!.*/$).*$

    – Wiktor Stribiżew
    Nov 20 '18 at 12:44











  • I've just checked this expression and it returns /server/webhelp/

    – GoldenAge
    Nov 20 '18 at 12:49













  • It does not, probably you have spaces after /? Then try /webhelp(?!.*/s*$).*$

    – Wiktor Stribiżew
    Nov 20 '18 at 12:49













  • I've just copied your expression and run the VS Code search engine. It's a pitty that there is no option to link a screenshot in the comment as a proof. I also set the "search.usePCRE2": true in the settings.json file. If this expression should work i don't have any idea why it doesnt, and what is the issue.

    – GoldenAge
    Nov 20 '18 at 12:56














3












3








3








I want to build regex expression in VS Code which returns all the phrases in the whole solution which contain a given string(please keep in mind that it can contain special characters) and not ends with given string e.g.
Contains /webhelp but not ends with /



Matches:



/server/webhelp

blah/webhelp#


Doesn’t match



/server/webhelp/

server#webhelp/


Im not an expert in Regex, I’ve tried to build something like:



(?=/webhelp)(?=.*(?<!/)$)


But it doesn’t work.










share|improve this question














I want to build regex expression in VS Code which returns all the phrases in the whole solution which contain a given string(please keep in mind that it can contain special characters) and not ends with given string e.g.
Contains /webhelp but not ends with /



Matches:



/server/webhelp

blah/webhelp#


Doesn’t match



/server/webhelp/

server#webhelp/


Im not an expert in Regex, I’ve tried to build something like:



(?=/webhelp)(?=.*(?<!/)$)


But it doesn’t work.







regex visual-studio-code






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 12:41









GoldenAgeGoldenAge

811223




811223













  • You already know that pcre2 option does not enable lookbehinds, why try them? Also, to match some string to highlight or remove it you need to consume the chars, and your regex only contains lookarounds.

    – Wiktor Stribiżew
    Nov 20 '18 at 12:42













  • Try /webhelp(?!.*/$).*$

    – Wiktor Stribiżew
    Nov 20 '18 at 12:44











  • I've just checked this expression and it returns /server/webhelp/

    – GoldenAge
    Nov 20 '18 at 12:49













  • It does not, probably you have spaces after /? Then try /webhelp(?!.*/s*$).*$

    – Wiktor Stribiżew
    Nov 20 '18 at 12:49













  • I've just copied your expression and run the VS Code search engine. It's a pitty that there is no option to link a screenshot in the comment as a proof. I also set the "search.usePCRE2": true in the settings.json file. If this expression should work i don't have any idea why it doesnt, and what is the issue.

    – GoldenAge
    Nov 20 '18 at 12:56



















  • You already know that pcre2 option does not enable lookbehinds, why try them? Also, to match some string to highlight or remove it you need to consume the chars, and your regex only contains lookarounds.

    – Wiktor Stribiżew
    Nov 20 '18 at 12:42













  • Try /webhelp(?!.*/$).*$

    – Wiktor Stribiżew
    Nov 20 '18 at 12:44











  • I've just checked this expression and it returns /server/webhelp/

    – GoldenAge
    Nov 20 '18 at 12:49













  • It does not, probably you have spaces after /? Then try /webhelp(?!.*/s*$).*$

    – Wiktor Stribiżew
    Nov 20 '18 at 12:49













  • I've just copied your expression and run the VS Code search engine. It's a pitty that there is no option to link a screenshot in the comment as a proof. I also set the "search.usePCRE2": true in the settings.json file. If this expression should work i don't have any idea why it doesnt, and what is the issue.

    – GoldenAge
    Nov 20 '18 at 12:56

















You already know that pcre2 option does not enable lookbehinds, why try them? Also, to match some string to highlight or remove it you need to consume the chars, and your regex only contains lookarounds.

– Wiktor Stribiżew
Nov 20 '18 at 12:42







You already know that pcre2 option does not enable lookbehinds, why try them? Also, to match some string to highlight or remove it you need to consume the chars, and your regex only contains lookarounds.

– Wiktor Stribiżew
Nov 20 '18 at 12:42















Try /webhelp(?!.*/$).*$

– Wiktor Stribiżew
Nov 20 '18 at 12:44





Try /webhelp(?!.*/$).*$

– Wiktor Stribiżew
Nov 20 '18 at 12:44













I've just checked this expression and it returns /server/webhelp/

– GoldenAge
Nov 20 '18 at 12:49







I've just checked this expression and it returns /server/webhelp/

– GoldenAge
Nov 20 '18 at 12:49















It does not, probably you have spaces after /? Then try /webhelp(?!.*/s*$).*$

– Wiktor Stribiżew
Nov 20 '18 at 12:49







It does not, probably you have spaces after /? Then try /webhelp(?!.*/s*$).*$

– Wiktor Stribiżew
Nov 20 '18 at 12:49















I've just copied your expression and run the VS Code search engine. It's a pitty that there is no option to link a screenshot in the comment as a proof. I also set the "search.usePCRE2": true in the settings.json file. If this expression should work i don't have any idea why it doesnt, and what is the issue.

– GoldenAge
Nov 20 '18 at 12:56





I've just copied your expression and run the VS Code search engine. It's a pitty that there is no option to link a screenshot in the comment as a proof. I also set the "search.usePCRE2": true in the settings.json file. If this expression should work i don't have any idea why it doesnt, and what is the issue.

– GoldenAge
Nov 20 '18 at 12:56












2 Answers
2






active

oldest

votes


















2














Here's a slightly shorter version of the regex:



/webhelp(?!/)


It simply matches '/webhelp' unless it's followed by a slash.






share|improve this answer
























  • Works for me thanks :)

    – GoldenAge
    Nov 20 '18 at 13:05



















3














Note that at this moment, lookbehinds are not yet supported by VSCode regex even when you have "search.usePCRE2": true set.



It seems the lookbehind support will be added sooner or later:




If you are still missing lookbehind assertions, don't worry! That feature is just recently supported by JavaScript and should come to VS Code in a later Electron shell update.




At this moment, you may use lookaheads. The regex that should match what you need is



/webhelp(?!.*/$).*$


enter image description here



Details





  • /webhelp - a literal substring


  • (?!.*/$) - a negative lookahead that makes sure the line does not end with /


  • .*$ - the rest of the line.


It still works even in Find in files:



enter image description here






share|improve this answer


























  • I checked this and it also works for me when I try to search in a single file. Don't know why it doesn't work for the global search engine(Ctrl+Shift+F).

    – GoldenAge
    Nov 20 '18 at 13:02













  • @GoldenAge My solution still works, I added another screen. The other solution does not check for / at the end of the line. Probably, you did not explain your requirements well.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:10













  • I've created the same project as you and your expression works properly in it but it doesn't work in my main project don't know why! This is very weird! Anyway, you have an upvote from me.

    – GoldenAge
    Nov 20 '18 at 13:31













  • @GoldenAge Ok, I see, it is fine. Let's hope the next release will have a more "stable" and cooler regex support. Happy coding.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:31













  • cheers and thanks for help ;)

    – GoldenAge
    Nov 20 '18 at 13:32











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393230%2fvisual-studio-code-regex-contains-but-not-ends-with%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Here's a slightly shorter version of the regex:



/webhelp(?!/)


It simply matches '/webhelp' unless it's followed by a slash.






share|improve this answer
























  • Works for me thanks :)

    – GoldenAge
    Nov 20 '18 at 13:05
















2














Here's a slightly shorter version of the regex:



/webhelp(?!/)


It simply matches '/webhelp' unless it's followed by a slash.






share|improve this answer
























  • Works for me thanks :)

    – GoldenAge
    Nov 20 '18 at 13:05














2












2








2







Here's a slightly shorter version of the regex:



/webhelp(?!/)


It simply matches '/webhelp' unless it's followed by a slash.






share|improve this answer













Here's a slightly shorter version of the regex:



/webhelp(?!/)


It simply matches '/webhelp' unless it's followed by a slash.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 12:57









Poul BakPoul Bak

5,48831233




5,48831233













  • Works for me thanks :)

    – GoldenAge
    Nov 20 '18 at 13:05



















  • Works for me thanks :)

    – GoldenAge
    Nov 20 '18 at 13:05

















Works for me thanks :)

– GoldenAge
Nov 20 '18 at 13:05





Works for me thanks :)

– GoldenAge
Nov 20 '18 at 13:05













3














Note that at this moment, lookbehinds are not yet supported by VSCode regex even when you have "search.usePCRE2": true set.



It seems the lookbehind support will be added sooner or later:




If you are still missing lookbehind assertions, don't worry! That feature is just recently supported by JavaScript and should come to VS Code in a later Electron shell update.




At this moment, you may use lookaheads. The regex that should match what you need is



/webhelp(?!.*/$).*$


enter image description here



Details





  • /webhelp - a literal substring


  • (?!.*/$) - a negative lookahead that makes sure the line does not end with /


  • .*$ - the rest of the line.


It still works even in Find in files:



enter image description here






share|improve this answer


























  • I checked this and it also works for me when I try to search in a single file. Don't know why it doesn't work for the global search engine(Ctrl+Shift+F).

    – GoldenAge
    Nov 20 '18 at 13:02













  • @GoldenAge My solution still works, I added another screen. The other solution does not check for / at the end of the line. Probably, you did not explain your requirements well.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:10













  • I've created the same project as you and your expression works properly in it but it doesn't work in my main project don't know why! This is very weird! Anyway, you have an upvote from me.

    – GoldenAge
    Nov 20 '18 at 13:31













  • @GoldenAge Ok, I see, it is fine. Let's hope the next release will have a more "stable" and cooler regex support. Happy coding.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:31













  • cheers and thanks for help ;)

    – GoldenAge
    Nov 20 '18 at 13:32
















3














Note that at this moment, lookbehinds are not yet supported by VSCode regex even when you have "search.usePCRE2": true set.



It seems the lookbehind support will be added sooner or later:




If you are still missing lookbehind assertions, don't worry! That feature is just recently supported by JavaScript and should come to VS Code in a later Electron shell update.




At this moment, you may use lookaheads. The regex that should match what you need is



/webhelp(?!.*/$).*$


enter image description here



Details





  • /webhelp - a literal substring


  • (?!.*/$) - a negative lookahead that makes sure the line does not end with /


  • .*$ - the rest of the line.


It still works even in Find in files:



enter image description here






share|improve this answer


























  • I checked this and it also works for me when I try to search in a single file. Don't know why it doesn't work for the global search engine(Ctrl+Shift+F).

    – GoldenAge
    Nov 20 '18 at 13:02













  • @GoldenAge My solution still works, I added another screen. The other solution does not check for / at the end of the line. Probably, you did not explain your requirements well.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:10













  • I've created the same project as you and your expression works properly in it but it doesn't work in my main project don't know why! This is very weird! Anyway, you have an upvote from me.

    – GoldenAge
    Nov 20 '18 at 13:31













  • @GoldenAge Ok, I see, it is fine. Let's hope the next release will have a more "stable" and cooler regex support. Happy coding.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:31













  • cheers and thanks for help ;)

    – GoldenAge
    Nov 20 '18 at 13:32














3












3








3







Note that at this moment, lookbehinds are not yet supported by VSCode regex even when you have "search.usePCRE2": true set.



It seems the lookbehind support will be added sooner or later:




If you are still missing lookbehind assertions, don't worry! That feature is just recently supported by JavaScript and should come to VS Code in a later Electron shell update.




At this moment, you may use lookaheads. The regex that should match what you need is



/webhelp(?!.*/$).*$


enter image description here



Details





  • /webhelp - a literal substring


  • (?!.*/$) - a negative lookahead that makes sure the line does not end with /


  • .*$ - the rest of the line.


It still works even in Find in files:



enter image description here






share|improve this answer















Note that at this moment, lookbehinds are not yet supported by VSCode regex even when you have "search.usePCRE2": true set.



It seems the lookbehind support will be added sooner or later:




If you are still missing lookbehind assertions, don't worry! That feature is just recently supported by JavaScript and should come to VS Code in a later Electron shell update.




At this moment, you may use lookaheads. The regex that should match what you need is



/webhelp(?!.*/$).*$


enter image description here



Details





  • /webhelp - a literal substring


  • (?!.*/$) - a negative lookahead that makes sure the line does not end with /


  • .*$ - the rest of the line.


It still works even in Find in files:



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 13:09

























answered Nov 20 '18 at 12:55









Wiktor StribiżewWiktor Stribiżew

319k16140222




319k16140222













  • I checked this and it also works for me when I try to search in a single file. Don't know why it doesn't work for the global search engine(Ctrl+Shift+F).

    – GoldenAge
    Nov 20 '18 at 13:02













  • @GoldenAge My solution still works, I added another screen. The other solution does not check for / at the end of the line. Probably, you did not explain your requirements well.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:10













  • I've created the same project as you and your expression works properly in it but it doesn't work in my main project don't know why! This is very weird! Anyway, you have an upvote from me.

    – GoldenAge
    Nov 20 '18 at 13:31













  • @GoldenAge Ok, I see, it is fine. Let's hope the next release will have a more "stable" and cooler regex support. Happy coding.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:31













  • cheers and thanks for help ;)

    – GoldenAge
    Nov 20 '18 at 13:32



















  • I checked this and it also works for me when I try to search in a single file. Don't know why it doesn't work for the global search engine(Ctrl+Shift+F).

    – GoldenAge
    Nov 20 '18 at 13:02













  • @GoldenAge My solution still works, I added another screen. The other solution does not check for / at the end of the line. Probably, you did not explain your requirements well.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:10













  • I've created the same project as you and your expression works properly in it but it doesn't work in my main project don't know why! This is very weird! Anyway, you have an upvote from me.

    – GoldenAge
    Nov 20 '18 at 13:31













  • @GoldenAge Ok, I see, it is fine. Let's hope the next release will have a more "stable" and cooler regex support. Happy coding.

    – Wiktor Stribiżew
    Nov 20 '18 at 13:31













  • cheers and thanks for help ;)

    – GoldenAge
    Nov 20 '18 at 13:32

















I checked this and it also works for me when I try to search in a single file. Don't know why it doesn't work for the global search engine(Ctrl+Shift+F).

– GoldenAge
Nov 20 '18 at 13:02







I checked this and it also works for me when I try to search in a single file. Don't know why it doesn't work for the global search engine(Ctrl+Shift+F).

– GoldenAge
Nov 20 '18 at 13:02















@GoldenAge My solution still works, I added another screen. The other solution does not check for / at the end of the line. Probably, you did not explain your requirements well.

– Wiktor Stribiżew
Nov 20 '18 at 13:10







@GoldenAge My solution still works, I added another screen. The other solution does not check for / at the end of the line. Probably, you did not explain your requirements well.

– Wiktor Stribiżew
Nov 20 '18 at 13:10















I've created the same project as you and your expression works properly in it but it doesn't work in my main project don't know why! This is very weird! Anyway, you have an upvote from me.

– GoldenAge
Nov 20 '18 at 13:31







I've created the same project as you and your expression works properly in it but it doesn't work in my main project don't know why! This is very weird! Anyway, you have an upvote from me.

– GoldenAge
Nov 20 '18 at 13:31















@GoldenAge Ok, I see, it is fine. Let's hope the next release will have a more "stable" and cooler regex support. Happy coding.

– Wiktor Stribiżew
Nov 20 '18 at 13:31







@GoldenAge Ok, I see, it is fine. Let's hope the next release will have a more "stable" and cooler regex support. Happy coding.

– Wiktor Stribiżew
Nov 20 '18 at 13:31















cheers and thanks for help ;)

– GoldenAge
Nov 20 '18 at 13:32





cheers and thanks for help ;)

– GoldenAge
Nov 20 '18 at 13:32


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393230%2fvisual-studio-code-regex-contains-but-not-ends-with%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)