b*
means "match zero or more occurences of b
".
.
means "match any character except newline".
[EE|EJU]
means "match an E
, a |
, a J
or a U
".
.*
means "match any character except newline zero or more times".
D
means "match a D
".
So the regex is doing what you asked it to do.
From the examples you provided in your question, I'm guessing that the actual rules should be:
- String starts with
KD-R35
.
- Then any number of alphanumeric characters may follow, as long as
- there is an
E
, a J
or a U
among them, and
- the string ends in
D
.
These rules, as a regex, read:
^ # start of string
KD-R35 # literal text
( # start of capturing group
\w* # any number of alphanumeric characters
[EJU] # at least one of E, J, or U
\w* # any number of alphanumeric characters
D # a D
) # end of capturing group
$ # end of string
or, in JavaScript:
match = subject.match(/^KD-R35(\w*[EJU]\w*D)$/i);
if (match != null) { // successful match
mytext = match[1] // capturing group 1
} else {
// Match attempt failed
}
I'm assuming that upper/lowercase don't matter.
EDIT: Erm, your new edit changes the rules. It seems that any string is allowed as long as it starts with KD-R35
and ends in D
. In this case, the regex would simply be /^KD-R35(\w*D)$/i
.