Try this regular expression:
^(A(B(C)?)?)?$
I think you can see the pattern and expand it for ABCD
and ABCDE
like:
^(A(B(C(D)?)?)?)?$
^(A(B(C(D(E)?)?)?)?)?$
Now each part depends on the preceeding parts (B depends on A, C depends on B, etc.).
More Related Contents:
- Regex – To allow numeric, only characters R, N, X, B, @ [closed]
- Regex for Email Address along with name format [duplicate]
- Negative lookbehind equivalent in JavaScript
- JavaScript regex multiline text between two tags
- Case insensitive regex in JavaScript
- I want to remove double quotes from a String
- Replace a Regex capture group with uppercase in Javascript
- Regular Expression | Leap Years and More
- List of all characters that should be escaped before put in to RegEx?
- Matching exact string with JavaScript
- Match any non-word character (excluding diacritics)
- Finding Plus Sign in Regular Expression
- Combining regular expressions in Javascript
- Why does String.match( / \d*/ ) return an empty string?
- RegEx: How can I match all numbers greater than 49?
- How can I replace newlines/line breaks with spaces in javascript?
- How do I split a string by whitespace and ignoring leading and trailing whitespace into an array of words using a regular expression?
- Remove specific HTML tag with its content from javascript string
- In a regular expression, match one thing or another, or both
- Regex only capturing last instance of capture group in match
- (*SKIP)(*FAIL) workaround in JavaScript RegExp
- What is the need for caret (^) and dollar symbol ($) in regular expression?
- Javascript RegExp for splitting text into sentences and keeping the delimiter
- Commenting Regular Expressions
- How to insert space every 4 characters for IBAN registering?
- How can I use regex to get all the characters after a specific character, e.g. comma (“,”)
- What’s different between Python and Javascript regular expressions?
- Extract keyword from Google search in Javascript
- Regex matching emoticons
- Regex: only alphanumeric but not if this is pure numeric