[WEBINAR] Application Acceleration: Faster Performance for End Users

Regular Expression

Definition - What does Regular Expression mean?

A regular expression is a method used in programming for pattern matching. Regular expressions provide a flexible and concise means to match strings of text. For example, a regular expression could be used to search through large volumes of text and change all occurrences of "cat" to "dog".

Regular expressions are used for syntax highlighting systems, data validation and in search engines such as Google, to try to determine an algorithmic match to the query a user is asking.

Regular expressions are also known in short form as regex or regexp.

Techopedia explains Regular Expression

Utilities, text editors and programming languages use regular expressions to manipulate and search patterns of text. While some languages integrate regular expressions into the core of the language syntax, like TCL, Awk, PERL and RUBY, others use regular expressions through libraries, such as Java, C++ and C. This means there are implementation differences so a regular expression that works well with one application might or might not work with another. Subtle differences do exist.

Regular expressions can be incredibly powerful. Essentially, if the pattern can be defined, a regular expression can be created. A simple pattern might be something as simple as finding all situations where a sentence ends in "that" and is replaced with "which". The pattern could get more complex by doing the same replacement but only on the 3rd and 5th occurrence of a match. Or it could get even more complicated by using different sets of matching characters depending on the frequency and location of previous matching characters.

The three main components of a regular expression are anchors that are used to specify the position of a pattern in relation to a line of text, character sets that match one or more characters in a single position, and modifiers that specify the number of times the previous character set is repeated.

The operations that help in building regular expressions are:
  • Quantification: Quantifiers dictate how often the preceding element is allowed to occur.
  • Grouping: Operators can have their scope and precedence specified using parentheses.
  • Boolean Conditions: An OR or AND condition can be stated for operators and groups.
Regular expressions use algorithms such as Deterministic Finite Automation (DFA) and Non-deterministic Finite Automation (NFA) to match a string. In an NFA, for each pair of state and input symbol there are several possible next states, while a DFA accepts a finite string of symbols.

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
"Techopedia" on Twitter

Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Free Whitepaper: The Path to Hybrid Cloud
Free Whitepaper: The Path to Hybrid Cloud:
The Path to Hybrid Cloud: Intelligent Bursting To Amazon Web Services & Microsoft Azure
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.