SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Location
    England
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regular expression - check for whitespace

    Hi, I am after a regular expression which checks for a specific whitespace in a string before a word in c#.

    What I mean if I have a string called "Hi, I am a woman".
    Problem is I want to check if a man the string is a man or woman.

    So I need a regex which checks for whitespace before 'man'.

    if (string == " man") = man else if (string == "man" = woman.

    any ideas?
    Read my blog...
    Skylight Studios

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    White space in regex is \s so the regular expression to match "man" but not "woman" would be
    Code Csharp:
    \sman

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Location
    England
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi thabks for your help, but i got got the pattern wrong.

    Problem is i was looking for a space before man but what if man starts at the beginning of a sentence? hence there is no space.

    I have corrected this but instead of looking for a space, then i look for any characters before the word 'man'. so for example wo-man then then show up as a match. If it were to match then it would return false.

    Any help?
    Read my blog...
    Skylight Studios

  4. #4
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code Csharp:
    ^man|\sman


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
  •