I am trying to write a PHP code to query the following values.
Consider the expression NAME like \”$string\” where,
$string should match,
ABC, //ABC can be followed by any characters (including special character)
ABCdef //ABC can be followed by any characters (including special character)
ABC //ABC followed by ONE Space
ABC df //ABC SPACE followed by anything
def ABC sda //ABC being start of a word
ABC //Just ABC
i.e. ABC should be the beginning of the string and should not be between any characters.
[edit]:
I tried something with wildcard characters like,
where $name like \"%$string%\" or like \"%string %\"
But it does not work.As I am new to PHP and regular expressions, can you help me in coming up with a solution.
Have you tried?
We check for “Start of string” (^) or Whitespace (\s) followed by ABC
Edit
Borrowing from @rodneyrehm, you might be looking for the SQL, not the PHP regex – in this case you need
or without a regex