Python Replace \\ with \ [duplicate]

There’s no need to use replace for this. What you have is a encoded string (using the string_escape encoding) and you want to decode it: >>> s = r”Escaped\nNewline” >>> print s Escaped\nNewline >>> s.decode(‘string_escape’) ‘Escaped\nNewline’ >>> print s.decode(‘string_escape’) Escaped Newline >>> “a\\nb”.decode(‘string_escape’) ‘a\nb’ In Python 3: >>> import codecs >>> codecs.decode(‘\\n\\x21’, ‘unicode_escape’) ‘\n!’

Remove a trailing slash from a string(changed from url type) in JAVA

There are two options: using pattern matching (slightly slower): s = s.replaceAll(“/$”, “”); or: s = s.replaceAll(“/\\z”, “”); And using an if statement (slightly faster): if (s.endsWith(“https://stackoverflow.com/”)) { s = s.substring(0, s.length() – 1); } or (a bit ugly): s = s.substring(0, s.length() – (s.endsWith(“https://stackoverflow.com/”) ? 1 : 0)); Please note you need to use … Read more

Is it possible to use “/” in a filename?

The answer is that you can’t, unless your filesystem has a bug. Here’s why: There is a system call for renaming your file defined in fs/namei.c called renameat: SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname) When the system call gets invoked, it does a path lookup (do_path_lookup) … Read more

Get value of a string after last slash in JavaScript

At least three ways: A regular expression: var result = /[^/]*$/.exec(“foo/bar/test.html”)[0]; …which says “grab the series of characters not containing a slash” ([^/]*) at the end of the string ($). Then it grabs the matched characters from the returned match object by indexing into it ([0]); in a match object, the first entry is the … Read more

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