We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Valid Username Regular Expression
Valid Username Regular Expression
Sort by
recency
|
489 Discussions
|
Please Login in order to post a comment
I’m tired of this regex challenge. Is it still an interview topic, and how often do you write it at work now that AI can do this quickly?
It’s a nice challenge to combine regex syntax with problem-solving in Java. Mahadev Book ID Login
"^[A-Za-z]" → first char must be a letter.
"[A-Za-z0-9_]{7,29}" → remaining chars must be alphanumeric or _, length between 7 and 29.
Total length = 1 (first char) + [7–29] = 8–30 characters.
Anchors ^...$ ensure no extra characters sneak in.
import java.util.Scanner;
public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); // use nextLine() here
}
import java.io.; import java.util.;
public class Solution {
}