Is there a RegExp.escape function in JavaScript?

The function linked in another answer is insufficient. It fails to escape ^ or $ (start and end of string), or -, which in a character group is used for ranges. Use this function: function escapeRegex(string) { return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, ‘\\$&’); } While it may seem unnecessary at first glance, escaping – (as well as ^) … Read more

Is it worth using Python’s re.compile?

I’ve had a lot of experience running a compiled regex 1000s of times versus compiling on-the-fly, and have not noticed any perceivable difference. Obviously, this is anecdotal, and certainly not a great argument against compiling, but I’ve found the difference to be negligible. EDIT: After a quick glance at the actual Python 2.5 library code, … Read more

How can I exclude one word with grep?

You can do it using -v (for –invert-match) option of grep as: grep -v “unwanted_word” file | grep XXXXXXXX grep -v “unwanted_word” file will filter the lines that have the unwanted_word and grep XXXXXXXX will list only lines with pattern XXXXXXXX. EDIT: From your comment it looks like you want to list all lines without … Read more

Regex Match all characters between two strings

For example (?<=This is)(.*)(?=sentence) Regexr I used lookbehind (?<=) and look ahead (?=) so that “This is” and “sentence” is not included in the match, but this is up to your use case, you can also simply write This is(.*)sentence. The important thing here is that you activate the “dotall” mode of your regex engine, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)