There is a regex pattern:
[a-zA-Z0-9]+.?(com|net)
I use it to replace the words in strings with this function:
const formatString = (str) => {
const regex = new RegExp("[a-zA-Z0-9]+.?(com|net)","gi");
return str.replace(regex, "*")
}
function execution examples:
formatString("google.com something else.net") // returns: "* something *"
formatString("google.com") // returns: "*"
formatString("something") // returns: "something"
but in some cases, I need to make an exception word so that it is not replaced.
Example:
exception word is google (or google.com)
formatString("google.com something else.net") // should returns: "google.com something *"
I tried to do it with negative lookahead using this pattern: (?!google)[a-zA-Z0-9]+.?(com|net), but it does not work, it only ignores the first letter of the word.
Match information from https://regex101.com/
