This might work: /^~.+|.+\/~.+/ (I’ve assumed the regex needs to match a whole path). This should match “a path starting with ~ followed by 1 or more of any characters” or a path starting with 1 or more of any character followed by a slash followed by a ~ followed by 1 or more of any characters. Or you could split it into 2 regexes: /^~.+/ and /.+\/~.+/.