#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0

    Little confused, don't work as expected...


    I have a regex like

    /^(?!(.*(<?php echo $text_string; ?>).*))/

    where the $text_string is

    HELP_GUIDE_TEXT|SOMEOTHER_INFO|YETAGAINSOMEOTHERINFO

    my regex does not allow HELP_GUIDE_TEXT_1

    I want to have a regex that does not accept a new name that is in the string, that is

    NOT HELP_GUIDE_TEXT - OR - SOMEOTHER_INFO - OR - YETAGAINSOMEOTHERINFO

    ...but...

    should accept something like

    HELP_GUIDE_TEXT_1 - OR - SOMEOTHER_INFO_1 - OR - YETAGAINSOMEOTHERINFO_1

    How do I do this?

    Thanx in advance!
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Just to be absolutely clear about what you're doing, what does your code look like?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0
    Code:
     /^(?!(.*(HELP_GUIDE_TEXT|SOMEOTHER_INFO|YETAGAINSOMEOTHERINFO).*))/
    I have a form, I want to validate the input.
    My code does not allow HELP_GUIDE_TEXT_1 or HELP_GUIDE_TEXT_2 or HELP_GUIDE_TEXT_3...

    I want to prevent adding a new string that is the EXACT same as an old one...
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Then your expression is simply trying too hard.
    Code:
    /^(HELP_GUIDE_TEXT|SOMEOTHER_INFO|YETAGAINSOMEOTHERINFO)$/
    and matches are bad. If the match has to be a good thing then wrap the group+$ in a negative assertion.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    9
    Rep Power
    0
    Maybe I am very unclear but what you show me validate that the input has to be in the string...

    I want the input NOT to be in the input...

    Any ideas?
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    Not in? Because you just said not exactly.

    Assuming you still mean not an exact match, yes: the expression I posted. If it matches then the input is not valid.

IMN logo majestic logo threadwatch logo seochat tools logo