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.
CodePudding user response:
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.
