0

I have a system written in PHP which aggregates records from a number of databases in to one. When doing this I need to detect if each record is ABNORMAL and if it is, flag it as being so.

To do this I need a pattern for preg_match() so it will return false if the given string contains the word NORMAL but not ABNORMAL. The string given may be over multiple lines.

The problem I am having is that the word ABNORMAL contains the word NORMAL.

Can anyone help?

1
  • Why not first search for ABNORMAL and then for NORMAL if the first search returns `false?
    – Blender
    Commented Dec 12, 2011 at 16:48

1 Answer 1

3

Use the word boundry character \b:

preg_match("|\bNORMAL\b|", $subject);

Note that it is case sensitive, the case insensitive version is this:

preg_match("|\bNORMAL\b|i", $subject);

Though if you have control over you database, you might want to use 0 and 1 (or at least N and A) instead of NORMAL and ABNORMAL.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.