Regex: ignore case sensitivity

Assuming you want the whole regex to ignore case, you should look for the i flag. Nearly all regex engines support it: /G[a-b].*/i string.match(“G[a-b].*”, “i”) Check the documentation for your language/platform/tool to find how the matching modes are specified. If you want only part of the regex to be case insensitive (as my original answer … Read more

How can I extract a number from a string in JavaScript?

For this specific example, var thenum = thestring.replace( /^\D+/g, ”); // replace all leading non-digits with nothing in the general case: thenum = “foo3bar5”.match(/\d+/)[0] // “3” Since this answer gained popularity for some reason, here’s a bonus: regex generator. function getre(str, num) { if(str === num) return ‘nice try’; var res = [/^\D+/g,/\D+$/g,/^\D+|\D+$/g,/\D+/g,/\D.*/g, /.*\D/g,/^\D+|\D.*$/g,/.*\D(?=\d)|\D+$/g]; for(var … Read more

Python string.replace regular expression [duplicate]

str.replace() v2|v3 does not recognize regular expressions. To perform a substitution using a regular expression, use re.sub() v2|v3. For example: import re line = re.sub( r”(?i)^.*interfaceOpDataFile.*$”, “interfaceOpDataFile %s” % fileIn, line ) In a loop, it would be better to compile the regular expression first: import re regex = re.compile(r”^.*interfaceOpDataFile.*$”, re.IGNORECASE) for line in some_file: … Read more

Regex to match only letters

Use a character set: [a-zA-Z] matches one letter from A–Z in lowercase and uppercase. [a-zA-Z]+ matches one or more letters and ^[a-zA-Z]+$ matches only strings that consist of one or more letters only (^ and $ mark the begin and end of a string respectively). If you want to match other letters than A–Z, you … Read more

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