Arrays and -contains – test for substrings in the elements of an array

It looks like your misconception was that you expected PowerShell’s -contains operator to perform substring matching against the elements of the LHS array. Instead, it performs equality tests – as -eq would – against the array’s elements – see this answer for details. In order to perform literal substring matching against the elements of an … Read more

match() returns array with two matches when I expect one match

From String.prototype.match [MDN]: If the regular expression does not include the g flag, returns the same result as regexp.exec(string). Where the RegExp.prototype.exec documentation [MDN] says: The returned array has the matched text as the first item, and then one item for each capturing parenthesis that matched containing the text that was captured. So as you … Read more

Content script matching top-level domains like all google.*

Listing all Google domains is not that difficult, because Google has published a list of all public Google domains at http://www.google.com/supported_domains. Prefix every item in this list with “*://* and add the “, suffix to every item. Then copy-paste the result to your manifest file. An alternative option is to use the “include_globs” field (this … Read more

Finding occurrences of a word in a string in python 3

If you’re going for efficiency: import re count = sum(1 for _ in re.finditer(r’\b%s\b’ % re.escape(word), input_string)) This doesn’t need to create any intermediate lists (unlike split()) and thus will work efficiently for large input_string values. It also has the benefit of working correctly with punctuation – it will properly return 1 as the count … Read more