Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /pattern/[switches]
- 1. Meta chars vs literals
- 2. Character classes [..]
- [abc] Character class, any character from a set of characters
- [^abc] Inverted char class, any character not in a set of characters
- [0-9] or [a-zA-Z] Any character in a range of characters
- 3. Quantifiers:
- x+ One or more occurrences of the pattern x
- x? Zero or one occurrence
- x* Zero or more occurrences
- x+? One or more occurrences, non-greedy
- x{n} Interval quantifier, matches exactly n times
- x{n,} At least n times
- x{n,m} Between n and m occurrences
- 4. backreferencing
- \n - A back reference to the last substring matching the n parenthetical
- in the regular expression (counting left parentheses).
- For example, /apple(,)\sorange\1/ matches 'apple, orange,' in "apple, orange, cherry, peach."
- . Any single character except newlines
- abc A sequence of characters
- (abc) A group
- a|b|c Any one of several patterns
- \d Any digit character
- \w An alphanumeric character (“word character”)
- \s Any whitespace character
- \b A word boundary
- ^ Start of input
- $ End of input
- ^$ line without chars
- 1. BACKREFFERENCING: Find word duplicates - /\b(\w+)\s+\1\b/
- This This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to validates_each will be tested against it it. In the following example, we don't want names and surnames to begin begin with lower case.
- 2. HTML: find target="_blank" attribute duplicate in html-php code - /<a.+?target="_blank".+?target="_blank".+?[^?]>/
- <a target="_blank" style="font-family:arial,sans-serif;font-size:15px;line-height:21px;color:#5f230a;text-decoration:none;" href="<?= $highlight['NewsLetter']['url'] ?>" target="_blank">
- 3. Email validation
- 4. BASICS::CHAR_CLASSES : find all word that has foo in the middle
- 5. BASICS::CHAR_CLASSES : regex that matches dates like 19.06.2000
- 6. Word in quotes /"[^"]*"/
- 7. Find price in $12.33 like in text: /\$[0-9]+(\.[0-9]+)?/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement