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

Posted on 2009-12-30
Last Modified: 2012-05-08
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?
Question by:zorba111
    LVL 84

    Accepted Solution

    \s does include the space character, and yes, a literal ' ' is also fine

    Author Comment

    gee that was fast!

    and just for completion, is there a metachar equivalent of ' ' (in the same way that \t represents a tab, etc.) ?
    LVL 84

    Expert Comment


    Author Comment

    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 ?

    Author Comment

    oops, my post crossed with yours - don't worry if there isn't a character combo - points are yours!

    ta v. much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
    Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now