Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

is there a metacharacter for the space character ' ' in regex?

is there a metacharacter for the space character ' ' in regex?

I went looking and thought the character class \s would help me find spaces, as its described as "matches any whitespace character" but on closer examination it is defined as the character set [\f\n\r\t\v]. Of the ones i'm not familiar with (\f = "form feed", \v = "vertical tab"), they couldn't also be masquerading as a space char, could they?

The book then gives an example of a pattern for a space or tab as [\t ], so presumably the literal ' ' character is fine? (I tried it in Dreamweaver's regex search and it worked, but is this a one-off, or is it a general rule?).

Just for completion, is there a metacharacter equivalent ?

Remark: its a bit surprising and randomly confusing that \s does not include the space character !!
Question: Maybe I'm missing something, so why would this be so?
0
zorba111
Asked:
zorba111
  • 3
  • 2
1 Solution
 
ozoCommented:
\s does include the space character, and yes, a literal ' ' is also fine
0
 
zorba111Author Commented:
gee that was fast!
thanks..

and just for completion, is there a metachar equivalent of ' ' (in the same way that \t represents a tab, etc.) ?
0
 
ozoCommented:
\040
0
 
zorba111Author Commented:
REason I ask is that my monitor ain't so great, and eyesight not good (maybe they are linked - there's a thought), so not always sure if typing one space char or 2x LOL

I suppose there is always the ascii code, if in either hex or octal if I got stuck...

space = 32,
hex = 0x20
octal = \040

However is there a neat little <backslash> + <character> trick, like \t etc ?
0
 
zorba111Author Commented:
oops, my post crossed with yours - don't worry if there isn't a character combo - points are yours!

ta v. much
gnight!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now