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

Convert columns to string in Pandas

One way to convert to string is to use astype: However, perhaps you are looking for the to_json function, which will convert keys to valid json (and therefore your keys to strings): Note: you can pass in a buffer/file to save this to, along with some other options…

How to convert a std::string to const char* or char*

If you just want to pass a std::string to a function that needs const char* you can use If you want to get a writable copy, like char *, you can do that with this: Edit: Notice that the above is not exception safe. If anything between the new call and the delete call throws, you will leak memory, as nothing will call delete for you … Read more

How to replace ” \ ” with ” \\ ” in java

Don’t use String.replaceAll in this case – that’s specified in terms of regular expressions, which means you’d need even more escaping. This should be fine: Note that the backslashes are doubled due to being in Java string literals – so the actual strings involved here are “single backslash” and “double backslash” – not double and quadruple. replace works on simple … Read more

Best way to replace multiple characters in a string?

Replacing two characters I timed all the methods in the current answers along with one extra. With an input string of abc&def#ghi and replacing & -> \& and # -> \#, the fastest way was to chain together the replacements like this: text.replace(‘&’, ‘\&’).replace(‘#’, ‘\#’). Timings for each function: a) 1000000 loops, best of 3: 1.47 μs per … Read more

Check if a variable is a string in JavaScript

You can use typeof operator: Example from this webpage. (Example was slightly modified though). This won’t work as expected in the case of strings created with new String(), but this is seldom used and recommended against[1][2]. See the other answers for how to handle these, if you so desire. The Google JavaScript Style Guide says to never use primitive object … Read more

How to split a string in Java

Just use the appropriate method: String#split(). Note that this takes a regular expression, so remember to escape special characters if necessary. there are 12 characters with special meanings: the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening parenthesis (, the closing … Read more

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