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

Forward slash or backslash?

Using forward slashes will make it system independent. I’d stick to that for simplicity. Consider using java.io.File.separator if you ever display the path to the user. You’d rather not surprise those Windows users. They’re a jumpy lot.

Python Replace \\ with \

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!’

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

tech