REGEXVAULTv2.0
Dev & Systems/File Paths
Verified Safe

POSIX File Permission Octal Regex for Java

/^([0-7]?)([0-7]{3})$/

What this pattern does

This page provides a lightweight, single-purpose regular expression for matching posix file permission octal, ported and verified for Java. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.

Java Implementation

Java
// POSIX File Permission Octal
// ReDoS-safe | RegexVault — Dev & Systems > File Paths

import java.util.regex.Pattern;

public class PosixFilePermissionOctalValidator {
    private static final Pattern PATTERN =
        Pattern.compile("^([0-7]?)([0-7]{3})$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("755")); // true
    }
}

Test Cases

Matches (Valid)
Rejects (Invalid)
755888
64499
77776
0008888
0755a644
47550855
2755
1777

When to use this pattern

This pattern is drawn from the Dev & Systems > File Paths category and carries a ReDoS-safe certification. That matters for Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Setting 777 on sensitive files is a security risk. The sticky bit on directories (1777) prevents users from deleting each other's files even with directory write permission.

Technical Notes

Optional leading digit: 4=setuid, 2=setgid, 1=sticky. Three digits: owner/group/other (read=4, write=2, execute=1). 1777 = /tmp permissions (sticky). 4755 = setuid root (dangerous). Group 1 = special bits, group 2 = rwx permissions.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern