bool3max
bool3max

Reputation: 2865

Match character group only if not at the end of the string

I've got this regex /^!balance ([^\s]+ ){3}/i. Basically the string should start with !balance, a space, and then exactly 3 words each separated with exactly one space. This, works but requires the string to also have one space at the end of the string.

!balance whatever whatever whatever ---> matches, but requires space after the last 'whatever'.

What should I add so that it matches without a space at the end?

Upvotes: 0

Views: 58

Answers (1)

Ira Rodens
Ira Rodens

Reputation: 111

Just turn the regex around, /^!balance( [^\s]+){3}/i to require a space at the beginning of the word. This will cover the space after balance by moving the space into the match group.

Upvotes: 2

Related Questions