background preloader

Regular Expression Tutorial

Regular Expression Tutorial
This tutorial teaches you all you need to know to be able to craft powerful time-saving regular expressions. It starts with the most basic concepts, so that you can follow this tutorial even if you know nothing at all about regular expressions yet. The tutorial doesn't stop there. It also explains how a regular expression engine works on the inside, and alert you at the consequences. This helps you to quickly understand why a particular regex does not do what you initially expected. What Regular Expressions Are Exactly - Terminology Basically, a regular expression is a pattern describing a certain amount of text. This first example is actually a perfectly valid regex. \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\. With the above regular expression pattern, you can search through a text file to find email addresses, or verify if a given string looks like an email address. Different Regular Expression Engines Give Regexes a First Try As a quick test, copy and paste the text of this page into EditPad Pro.

SLRE - Super Light Regular Expression library F Sharp Programming/Computation Expressions - Wikibooks, collection of open-content textbooks Computation expressions are easily the most difficult, yet most powerful language constructs to understand in F#. Monad Primer[edit] Computation expressions are inspired by Haskell monads, which in turn are inspired by the mathematical concept of a monads in category theory. Note: The designers of F# use term "computation expression" and "workflow" because it's less obscure and daunting than the word "monad." Monads in Haskell Haskell is interesting because it's a functional programming language where all statements are executed lazily, meaning Haskell doesn’t compute values until they are actually needed. Consequently, it's quite a challenge to do things which need to be executed in a sequence, which includes any form of I/O, acquiring locks objects in multithreaded code, reading/writing to sockets, and any conceivable action which has a side-effect on any memory elsewhere in our application. Visualizing Monads with F# If you can understand this much, then you can understand any monad.

PCRE - Perl Compatible Regular Expressions Computation Expressions (F#) You can define the characteristics of your own computation expressions by creating a builder class and defining certain special methods on the class. The builder class can optionally define the methods as listed in the following table. The following table describes methods that can be used in a workflow builder class. Many of the methods in a builder class use and return an M<'T> construct, which is typically a separately defined type that characterizes the kind of computations being combined, for example, Async<'T> for asynchronous workflows and Seq<'T> for sequence workflows. The signatures of these methods enable them to be combined and nested with each other, so that the workflow object returned from one construct can be passed to the next. The compiler, when it parses a computation expression, converts the expression into a series of nested function calls by using the methods in the preceding table and the code in the computation expression.

How lexers (e.g. from LEX) and parsers (e.g. from YACC or JAVACC) work Next: Ambiguous and confusing grammars Up: CS2121: The Implementation and Previous: YACC: Further usage Subsections How lexers and parsers work Lexers - Finite State Automata (FSA) Lexers are also known as scanners. which has states 0 to 3, where state 0 is the initial state and state 3 is an accept state that indicates a possible end of the pattern. LEX implements this by creating a C program that consists of a general algorithm: and a decision table specific to the DFSA: This table is indexed by the current state and input character, and used by the algorithm to decide which of the alternative actions to choose, and the new state after a match (the number in brackets in the table above). FLEX makes its decision table visible if we use the -T flag, but in a very verbose format. Parsers - Deterministic Push Down Automata (PDA) There are two important classes of parsers, known as top-down parsers and bottom-up parsers, and we are going to look at both in a bit more detail. Top-Down Parsers

Some Details on F# Computation Expressions - Don Syme&#039;s WebLog on F# and Related Topics attempt.Delay(fun () -> attempt.Bind(f inp1,(fun n1 -> attempt.Bind(f inp2,(fun n2 -> attempt.Let(n1 + n2,(fun sum -> attempt.Return(sum)))))))) In this case, we're assuming that "attempt" has type type AttemptBuilder = member Bind : Attempt<'a> * ('a -> Attempt<'b>) -> Attempt<'b> member Delay : (unit -> Attempt<'a>) -> Attempt<'a> member Let : a * ('a -> Attempt<'a>) -> Attempt<'a> member Return : 'a -> Attempt<'a> We can define the builder object "attempt" as follows: let succeed x = (fun () -> Some(x)) let fail = (fun () -> None) let runAttempt (a:Attempt<'a>) = a() let bind p rest = match runAttempt p with None -> fail | Some r -> (rest r)let delay f = (fun () -> runAttempt (f ())) type AttemptBuilder() = /// Wraps an ordinary value into an Attempt value. /// Used to de-sugar uses of 'return' inside computation expressions. member b.Return(x) = succeed x /// Composes two attempt values. let failIfBig n = attempt { if n > 1000 then return! let sumIfBothSmall (inp1,inp2) = attempt { let! let!

Mini-XML About Mini-XML Mini-XML is a small XML library that you can use to read and write XML and XML-like data files in your application without requiring large non-standard libraries. Mini-XML only requires an ANSI C compatible compiler (GCC works, as do most vendors' ANSI C compilers) and a 'make' program. Mini-XML supports reading of UTF-8 and UTF-16 and writing of UTF-8 encoded XML files and strings. Data is stored in a linked-list tree structure, preserving the XML data hierarchy, and arbitrary element names, attributes, and attribute values are supported with no preset limits, just available memory. Mini-XML 2.8 Jan 5, 2014 Mini-XML 2.8 is now available for download from: Mini-XML 2.8 fixes some minor platform and XML issues. Now call docsetutil using xcrun on OS X (Bug #458) mxmldoc did not escape special HTML characters inside @code foo@ comments. Post comment Mini-XML 2.7 Dec 21, 2011 Mini-XML 2.7 is now available for download from: Enjoy!

Common Regular Expressions | PHP Reference Book Blog I’ve gotten better and more comfortable with regular expressions as time has passed, and sometimes I spend timing wading through google for some common regular expressions I want to put into use, because I’m sure someone has already created it. Well, this isn’t always true (or easy to find), so I decided to collect some common Regular Expressions that may benefit readers. It’s a good idea to keep two things handy if you want to play with Regular Expressions yourself: Date and Time RegEx Time format (no seconds): HH:MM am/pm Date in mm/dd/yyyy format, with an option for m/d/yyyy (exclude zero’s) Date in dd/mm/yyyy format, with an option for d/m/yyyy (exclude zero’s) Demographics RegEx Age in years – max 122 Height in Feet and Inches: 6’3″ Contact Information RegEx U.S. U.S. Email Address – (use preg_match) credit goes to fightingforalostcause.net Currency RegEx Currency – U.S. Currency – British Pounds with commas for multiple’s of 1000 and a period for the decimal: £12,000.23 Similar Posts:

argtable - ANSI C command line parser The Wayward WebLog : LINQ: Building an IQueryable Provider - Part I public class Query<T> : IQueryable<T>, IQueryable, IEnumerable<T>, IEnumerable, IOrderedQueryable<T>, IOrderedQueryable { QueryProvider provider; Expression expression; public Query(QueryProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); this.provider = provider; this.expression = Expression.Constant(this); public Query(QueryProvider provider, Expression expression) { if (expression == null) { throw new ArgumentNullException("expression"); if (! throw new ArgumentOutOfRangeException("expression"); this.expression = expression; Expression IQueryable.Expression { get { return this.expression; } Type IQueryable.ElementType { get { return typeof(T); } IQueryProvider IQueryable.Provider { get { return this.provider; } public IEnumerator<T> GetEnumerator() { return ((IEnumerable<T>)this.provider.Execute(this.expression)).GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this.provider.Execute(this.expression)).GetEnumerator(); try { return null;

parsing - lexers vs parsers Future Expressions Last post, I looked at what Expression offered in C# 3.5; to re-cap, very versatile at building simple queries, but not useful for writing manipulation code - in particular, the only in-built assignment is via Expression.MemberInit etc, which is useful only when creating new objects - or at a push you can perform a single update by obtaining the setter and using Expression.Call. The interesting news is that this looks very different in .NET 4.0 (based on the public October 2008 CTP). It appears that Expression underpins much of the DLR / dynamic work - so there are all sorts of interesting new options - essentially, Expression is the new CodeDOM... personally I am very excited about this; I've always found Expression a far more intuitive and workable abstraction than the counterparts. The new entries (again, based on the CTP) are: I won't pretend to understand them much yet, but I will be investigating! Expression<Action<Foo>> action = foo => { foo.Bar = "def"; Console.WriteLine(foo); };

Related: