My current regex looks for a searchQuery
inside sentences and matches them if those queries start a with a blank space, and end with either a blank space or ?!,.
. It generally works well, except for URLs. The regex ends up picking up urls and messing them up.
For example, if I was looking for "bitcoin" in a sentence "Bitcoin price is going nuts", it would find it, but it was also take the following url and match it.
https://versionone.vc/the-solar-
bitcoin-convergence
, messing up the url.
How can I tell JavaScript Regex to ignore any matches where the character before the matching words is either of these / - . _ +
? This will essentially eliminated matches inside urls?
Current Regex:
var reg = new RegExp('(\\b)${searchQuery}(\\s+|\\.|\\,|\\?|\\!', 'gi');
Replacement function:
newString = oldString.replace(reg, substringReplacement);
substringReplacement(match)
is a function that contains the logic of how to change the matching text.
Alternatively, what's another way to outright ignore urls from the searchable area. Thanks!