SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: RegEx question

  1. #1
    SitePoint Zealot TheMonk's Avatar
    Join Date
    Oct 2005
    Location
    Canada
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RegEx question

    First off, sorry if this is the wrong forum but I wasn't sure where to post this.

    I'm trying to learn RegEx and I'm having some problems detecting white space.

    When I enter a white space character I'm able to match it using either [ ] or \s but I've tried using all of the other special characters to match it such as \n \t etc and nothing matches it.

    I'm assuming a space is called a line feed? And how do you detect a white space using RegEx?

  2. #2
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    \s matches all types of whitespace. This includes tabs, newlines, and such.

    Use [ ] if you wanted to match a space.

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,264
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    whitespace

    From the perspective of typewriters (what word processing evolved from)
    a space is simply a space - " "
    linefeed goes to the next line, below where the line above ended.
    carriage return goes to the beginning of the same line.
    carriage return, linefeed, goes to the beginning of the next line.

    Some systems use \r\n - carriage return, line feed, to explicitly specify the beginning of the next line, but some systems "know what you mean" and don't require both.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •