java - Error in Regular expression for find File according a Pattern -
i need develop pattern in regular expression:
pattern:
201410021600(12 numbers)-only 2 options or b_(zz same)616048(6 numbers)_bbbb(4 characters)-123456abcdef(12 alfanumeric)_out(always same).pdf(always same)
real example:
201410021600-a_zz123456_bbbb-123456abcdef_out.pdf.
this attempt, didn,t work :(:
\d{12}-{1}a_{1}\bzz\b\d{6}_{1}\d{4}-{1}\w{12}_{1}\bout.pdf\b
somebody can help me, please?
you don't need specify quantity 1, i.e. instead of -{1}
or _{1}
-
or _
sufficient.
additionally, you're specifying quantity twice here: \d{6}{1}
not necessary.
third, \b
marks word boundary means there needs @ to the lowest degree whitespace. \bzz\b
won't match input.
applying this, regex looks , should work: \d{12}-[ab]_zz\d{6}_[a-z]{4}-[a-z0-9]{12}_out\.pdf
to break down:
201410021600(12 numbers)
-> \d{12}
-only 2 options or b
-> -[ab]
update: comment seems if a
, b
words , not characters, can't utilize character class here need utilize grouping instead, e.g. -(?>a|b)
((?>...)
means grouping non-capturing, i.e. can't retrieve using matcher.group(x)
etc.) _(zz same)
-> _zz
616048(6 numbers)
-> \d{6}
_bbbb(4 characters)
-> _[a-z]{4}
(i assume upper case chars allowed) -123456abcdef(12 alfanumeric)
-> -[a-z0-9]{12}
(in case upper case characters allowed) _out(always same)
- > _out
.pdf(always same)
-> \.pdf
(the dot matches character needs escaped) if case not matter, i.e. if 201410021600-a_zz123456_bbbb-123456abcdef_out.pdf.
should match well, either add together a-z
character classes should allow lower case (e.g. [a-za-z]
instead of [a-z]
) or add together (?i)
@ front end of look if lower case allowed.
java regex
No comments:
Post a Comment