Reputation: 91
I need to match 4 to 60 characters, space, single quote, and exclude trailing spaces.
Cases:
I need to exclude trailing spaces from this regex
^[\\w\'\ ]{4,60}$
[ \t]+$
- don't know how to add this to this regex
Upvotes: 1
Views: 96
Reputation: 163477
You might use a pattern where the repeating parts starts with either a space or tab. At the start of the pattern, you could assert a length of 4 - 60 chars using a positive lookahead.
^(?=[\w' \t]{4,60}$)[\w']+(?:[ \t][\w']+)*$
const pattern = /^(?=[\w' \t]{4,60}$)[\w']+(?:[ \t][\w']+)*$/;
[
"aa aa",
"tes'",
"not ",
"asdpijfaousdhfaoijsdgohasd' asdfa adsfads"
].forEach(s =>
console.log(`${s} --> ${pattern.test(s)}`)
)
Upvotes: 3