Reputation: 29
I want to create a regular expression for a string of maximum length 12.
The string is following this pattern: ####{value}#####
where #
could be $
, %
, &
, *
and \n
or space. And {value}
is a constant string that will always be present. The number of #
will vary.
For example
####{value}
###{value}#
##{value}##
#{value}###
{value}
####
(with newline)
I came up with
/^([\*#$%&\s]+{value}+[\*#$%&\s]){0, 12}$/
but it's not working.
Upvotes: 1
Views: 36
Reputation: 521339
I would use a positive lookahead to limit the length to a maximum of 12 characters.
^(?!.{13})[*#$%&\s]*.+[*#$%&\s]*$
You may sandwich any value you wish between the two character classes of symbols.
Upvotes: 2