SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Regex help!

  1. #1
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex help!

    I need seperate regular expression to match the following:

    All non special characters EXCEPT ' and - (match df&g but not ab-tg or df')
    Any match from a list of strings e.g. "aka", "nee", "n/k" - either on their own or followed by a space (match "nee smith" or "aka jones" or "n/k" but not "Paneen" or "Pakah")
    Two spaces in a row
    Two hypens in a row

    Cheers
    monkey - the rest is history

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,343
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    The "list of strings" is handled with an OR operation (using the Pipe symbol)
    Code:
    /[nee|aka|n\/k]/
    You can match all 'non special' characters with this:
    Code:
    /[\D\S]/
    I *believe* your requirement will be met with this:
    Code:
    /[\D\S^\'^\-]/
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first will match 'McNe'e won't it? I don't want this, the string must be on it's own or followed by a space.

    The second matches any no digit or non-space! I want to match any special characters EXCEPT ' and - such as [\\W^\\s^\\'^\\-] - this doesn't work!
    monkey - the rest is history


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
  •