Regex "does not start with XX"

Solved
zoipod Posted messages 2 Registration date   Status Member Last intervention   -  
zoipod Posted messages 2 Registration date   Status Member Last intervention   -
Hello,

I want to set up a regex using preg_match that would return true if a variable DOES NOT start with a word (not just a single letter)

I'm not an expert in regex, I've heard about assertions but they seem too complex for me..

Important thing: I must do it with a regex (using strpos would have been done already.. but I can't.. The preg_match is already present in a script, and the regex has to be stored in the database)

Thank you.

2 answers

  1. jordane45 Posted messages 30427 Registration date   Status Moderator Last intervention   4 831
     
    Hello,

    Wouldn't something like this do the trick?:

    ^(?!YourWord).*


    --
    Best regards,
    Jordane
    8
  2. zoipod Posted messages 2 Registration date   Status Member Last intervention  
     
    Indeed, quite simply.

    My final regex is:
    ^(?!AN)^(?!AM)

    (Does not start with AN or AM)

    Thank you very much!
    0