Bloom Lab
Pages
Home
Bloom Code Guidelines
Friday, October 23, 2015
Keynote: Regexp Short Notes
Regular expressions
Regular expression is a pattern describing a certain amount of text. So, Regexps are quite useful whatever programming language u're using.
---- ## Regexp Basics Regular Expression Patterns : * `.` - any char;`[A-Za-z]` - any char within brackets; `[^abc]` - any char except ones*("abc")* within brackets; `( )` - marked subexpression. * `*` - zero or more instances; `?` - zero or one time; `+` - one or more times. * `\n` - matches *nTh* match; `{m,n}` - matches at least *m* and not more than *n* times. * `|` - alternation, matcher either the expression before or after operator. `cat|dog` matches "cat" or "dog". * `^` - start position within string/line; `$` - end position within string/line. * `\s` - whitespace; `\S` - anything but whitespace; `\d`/`\D` - digit/not digit. * `\w`/`\W` alphabetic char & `_` symbol / excluding any alphabetic char & `_` symbol. ---- ## Regexp Lookarounds ### Look between excluding Use `[^u]` where `u` is the symbol that will be excluded from search. Grab everything between `A` & `C` but not include those: **pattern:** `\[^A].*[^C]\g` **text1:** AA**BBDD**CC **text2:** A**EABBDDCE**C ### Lookahead-positive Matches a group after the expression without including it in the result. `q(?=u)` grabs `q` only if it's immediately followed by `u`. Grab only `B`, which is followed by `D`: **pattern:** `\B(?=D)\g` **text:** AAB**B**DDCC ### Lookahead-negative Specifies a group that can not match after the expression. `q(?!u)` grabs `q` only if it's not immediately followed by `u`. Grab only `B`, which is not followed by `D`: **pattern:** `\B(?!D)\g` **text:** AA**B**BDDCC ### Lookbehind-positive & Lookbehind-negative Accordingly `(?<=u)q` & `(?
1 comment:
am0wa
April 27, 2016 at 1:15 PM
This comment has been removed by the author.
Reply
Delete
Replies
Reply
Add comment
Load more...
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
This comment has been removed by the author.
ReplyDelete