Oliver Kucharzewski
Oliver Kucharzewski

Reputation: 2645

Including Capital & Non Capital Letters in Regex

I'm attempting to create an SQL filtering system which notifies the user when the request contains any of the included words.

Currently my regex only supports all caps & I was wondering whether it would be possible to have it also accept non-caps as-well as other combinations of letters for example SElEcT

I understand entering this manually would be possible, however, this is not the most productive way to perform such a task.

This is my current code:

function checkString($string)
{
if(preg_match('[SELECT|FROM|DATABASE|TABLE|DROP|ALTER|LIKE|IN|BETWEEN|UNION|NULL|CHECK|JOIN|AVG|SUM|COUNT|FIRST|LAST|MAX|MIN|GROUP]', $string

Thanks.

Upvotes: 2

Views: 425

Answers (1)

Terence Johnson
Terence Johnson

Reputation: 1647

Use the i modifier (makes the regex case insensitive.):

if(preg_match('/(SELECT|FROM|DATABASE|TABLE|DROP|ALTER|LIKE|IN|BETWEEN|UNION|NULL|CHECK|JOIN|AVG|SUM|COUNT|FIRST|LAST|MAX|MIN|GROUP)/i', $string

More info

Upvotes: 6

Related Questions