How do you write the following strings with regex? .. and /.. and ..anyalphanumeric0

I would like to write a code, that escapes everything which could mean a "parent directory" in relative path. So my code would be something like this in pseudo code:

if (!regex_matches(".." , template_str) && !regex_matches("*/.." , template_str) && anything else) {
    do something
}

Where the first regex matches exactly 2 dots, the second regex matches anything that ends with "/..", and the regex does not match any string, that has ".." in it, like "apple..banana". How to do this?



Read more here: https://stackoverflow.com/questions/66342570/how-do-you-write-the-following-strings-with-regex-and-and-anyalphanume

Content Attribution

This content was originally published by DANIEL at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: