Regex how to match an optional character

Use to make the letter optional. {1} is redundant. (Of course you could also write [A-Z]{0,1} which would mean the same, but that’s what the ? is there for.) You could improve your regex to And, since in most regex dialects, \d is the same as [0-9]: But: do you really need 11 separate capturing groups? And if so, why don’t you capture the … Read more

string to string array conversion in java

To start you off on your assignment, String.split splits strings on a regular expression and this expression may be an empty string: Yields the array: Getting rid of the empty 1st entry is left as an exercise for the reader 🙂 Note: In Java 8, the empty first element is no longer included.

Regex not operator

No, there’s no direct not operator. At least not the way you hope for. You can use a zero-width negative lookahead, however: The (?!…) part means “only match if the text following (hence: lookahead) this doesn’t (hence: negative) match this. But it doesn’t actually consume the characters it matches (hence: zero-width). There are actually 4 … Read more

Regex not operator

No, there’s no direct not operator. At least not the way you hope for. You can use a zero-width negative lookahead, however: The (?!…) part means “only match if the text following (hence: lookahead) this doesn’t (hence: negative) match this. But it doesn’t actually consume the characters it matches (hence: zero-width). There are actually 4 combinations of lookarounds with 2 axes: lookbehind / lookahead : … Read more

working of \n in python [duplicate]

There are two functions that give an object’s string representation, repr() and str(). The former is designed to convert the object to as-code string, while the latter gives user-friendly string. When you input the variable name in the command line, repr() is used, and \n character is shown as \n (as-code). When you use print, … Read more

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