SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    quick question - preg_match

    hey guys i got the following preg_match
    Code:
    preg_match('/[^a-z0-9 ]/i', $title)
    which checks if there's space / a-z / 0-9 in the string...

    Now i want to add another character '|', where in the code above do i need to add it so it'll work properly?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Have you actually tried just sticking it in there next to the other characters you're checking for?

    PS: This function as written will check if there's anything EXCEPT a-zA-Z0-9 and space in the string.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PS: This function as written will check if there's anything EXCEPT a-zA-Z0-9 and space in the string.
    Yeah thats what i meant, my bad :P

    Have you actually tried just sticking it in there next to the other characters you're checking for?
    Yes i tried it like this:
    Code:
    preg_match('/[^a-z0-9| ]/i', $title)
    didnt seemed to work thought

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    So you put in "This is a | test" and it comes out with a number?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hmm u right with ur example it does work, i tried with an example in hebrew which didnt, probably encoding issue, ill have to take a deeper look

    nother question regarding this, if i want to adda also '-' character, ill have to do it like that? '\-'

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ulthane View Post
    hmm u right with ur example it does work, i tried with an example in hebrew which didnt, probably encoding issue, ill have to take a deeper look

    nother question regarding this, if i want to adda also '-' character, ill have to do it like that? '\-'
    So you put something in that wasnt in [a-zA-Z0-9| ] and it came out with a number that wasnt -1. Sounds like it did exactly what it's supposed to.

    To add - to the pattern, yes, you would have to escape it as \-
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Member
    Join Date
    Feb 2012
    Location
    Switzerland
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just because I learned so much there, some related links..

    Wonderfull tool to learn and test regex
    http://gskinner.com/RegExr/
    give it a try and put it in bookmarks - I use it reguarly..

    also usefull
    http://txt2re.com/

    regards
    Hensel


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
  •