Match whitespace not newline

I’ve just been modifying a Lua pattern to try to get it to match " " but not “\n”. Unfortunately the %s character class matches both, and I wanted something more elegant than sticking a space in the pattern itself. 

My current solution has been the rather inelegant [^%c%d%a] pattern (i.e. not a control character and not a digit and not a letter). 

Anyone know of any better solutions? The test case is:

[lua]

assert((" “):find(pattern)~=(”\n"):find(pattern))

[/lua]

Sticking a space in it is less “elegant” than using [^%c%d%a]? :slight_smile:

You should just do this:

[lua]

local whiteSpacePattern = “[\t]”

[/lua]

If you’re having trouble with the “elegance” of that pattern, just imagine some dignified upper-class Victorian English woman with a pince-nez looking at you every time you see it.

  • Caleb

Ah, didn’t realise Lua accepted \t to represent tab. Thanks!

No problem :slight_smile:

  • Caleb

Hello, everyone.I am Shelly, hope I could make friends with all of you here. And discuss some games with you, thanks a lot!

____________

iqbal

Sticking a space in it is less “elegant” than using [^%c%d%a]? :slight_smile:

You should just do this:

[lua]

local whiteSpacePattern = “[\t]”

[/lua]

If you’re having trouble with the “elegance” of that pattern, just imagine some dignified upper-class Victorian English woman with a pince-nez looking at you every time you see it.

  • Caleb

Ah, didn’t realise Lua accepted \t to represent tab. Thanks!

No problem :slight_smile:

  • Caleb

Hello, everyone.I am Shelly, hope I could make friends with all of you here. And discuss some games with you, thanks a lot!

____________

iqbal