For example if i want to retrieve all dots "." The answer I gave will work in JavaScript, which does not support look-behind.Although not the quickest answer, +1 for the explanation! Find all words that end in 'friend' that don't start with the word 'girl' in the following sentence:Here's another non-obvious approach which should work in any modern implementation of regular expressions: Assuming you wish to extract a pattern which appears within multiple contexts but you only want to match if it appears in a specific context, you can use an alteration where you first specify what you don't want and then capture what you do.So, using your example, to extract all of the words that either are or end in I changed Rob Raisch's answer to a regexp that finds words Containing a specific substring, but not also containing a different specific substringThanks for contributing an answer to Stack Overflow! Also, a "boundary" is the (IMO) better word here since it is then clear that it is a "zero-width" pattern (it matches no character, just a position). Note that it's very easy to see if something does start with a certain value, just use the anchor-to-first-start char '^'. It does not seem to work with non alphanumeric chars. It doesn't match "girlfriend" when I test in Expresso.Correct, it does not match the word "friend" with the word "girl" in front of it. Match string not containing string Given a list of strings (words or other characters), only return the strings that do not match. This regex is meant to match strings that DO NOT START WITH a specified string. ... (? Try it! The Overflow Blog Regular Expression to Only matches strings that do NOT start with a given string. Problem is that it also matches an empty string. Help us improve MSDN. Case sensitive. --> should detect dot after "Hello" and at the end of the sentence but not in "@some.thing"). By using our site, you acknowledge that you have read and understand our for example "FBI_" This site uses cookies for analytics, personalized content and ads.

Stack Overflow for Teams is a private, secure spot for you and For example if i want to retrieve all dots "." Small nitpick though: @BartKiers, true but in this instance it serves the purpose of delimiting the start and end of the word.sure, I know. --> should detect dot after "Hello" and at the end of the sentence but not in "@some.thing"). By using that textbox, the user only can key in numeric. @some.thing is not working .

@some.thing is not working . But the fact that your first called it "start" and then the 2nd one "end" might lead one to believe they match different things on different places. Any idea on how to modify it to not match an empty string? The content you requested has been removed. except in the words starting with "@". What I meant is that in case of the word "boyfriend", only the word "friend" is matched. for example "FBI_" ^(?i)([^(FBI_)]) (note use of case insensitive inline option).