Regular Expressions

(.*) . mean any character (number,alpha,special) * means zero or more times

Recipes

Match any character but white space - min of 6 characters preg_match('/^\S{6,}\z/', $string)

Notes

$ matches end of string or before a line break at end of string (if no modifiers are used) \z matches end of string (independent of multiline mode)

What is lookbehind and look ahead?

Negative Lookaheads Match a Q not followed by a U: q(?!u).

Positive Lookaheads Match a Q followed by a U: q(?=u)

*

What is greediness?

http://www.regular-expressions.info/lookaround.html

Apps

http://www.rwe-uk.com/app/oyster

Patterns

youtube: { pattern: /^((http(s)?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|v\/)?)([a-zA-Z0-9-]+)(.*)?$/, replace: 'http://www.youtube.com/v/$7&fs=1' } 

Jquery

Gotchas

  • .replace has no quotes in the first parameter

Remove hashtag

hashtag = $("#hash_edit").text();
return hashtag.toLowerCase().replace(/#/g,'');

What is lookbehind and look ahead?

Negative Lookaheads Match a Q not followed by a U: q(?!u).

Positive Lookaheads Match a Q followed by a U: q(?=u)

*

What is greediness?

http://www.regular-expressions.info/lookaround.html

Apps

http://www.rwe-uk.com/app/oyster

http://www.phpliveregex.com/ https://regex101.com/ http://regexr.com/