Thursday, January 20, 2011

Regular Expression Samples

Regx Expression for removing repeated words (case insensitive)

$text = preg_replace("/\s(\w+\s)\1/i", "$1", $text);

Output : ‘Keep your your head’ becomes ‘Keep your head’

Password complexity

Tests if the input consists of 6 or more letters, digits, underscores and hyphens.
The input must contain at least one upper case letter, one lower case letter and one digit.

'\A(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])[-_a-zA-Z0-9]{6,}\z'

No comments:

Post a Comment

Customizing the Search form - Drupal

To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the fo...