REGULAR
EXPRESSIONS(POSIX)
BY
SANA MATEEN
Brackets
• Regular expressions provide the foundation for describing or matching data
according to defined syntax rules.
• There are three methods that POSIX supports for locating different
character sequences: brackets, quantifiers, and predefined character
ranges.
• Brackets ([]) are used to represent a list, or range, of characters to be
matched.
• For instance, the regular expression [php] will find any string containing
the character p or h. Several commonly used character ranges follow:
• [0-9] matches any decimal digit from 0 through 9.
• [a-z] matches any character from lowercase a through lowercase z.
• [A-Z] matches any character from uppercase A through uppercase Z.
• [A-Za-z] matches any character from uppercase A through lowercase z.
Quantifiers
• Here are several examples of these characters:
• p+ matches any string containing at least one p.
• p* matches any string containing zero or more p’s.
• p? matches any string containing zero or one p.
• p{2} matches any string containing a sequence of two p’s.
• p{2,3} matches any string containing a sequence of two or three p’s.
• p{2,} matches any string containing a sequence of at least two p’s.
• p$ matches any string with p at the end of it.
• Still other flags can be inserted before and within a character sequence:
• ^p matches any string with p at the beginning of it.
• [^a-zA-Z] matches any string not containing any of the characters ranging from
a through z and A through Z.
• p.p matches any string containing p, followed by any character, in turn
followed by another p.
• You can also combine special characters to form more complex expressions.
Consider the following examples:
• ^.{2}$ matches any string containing exactly two characters.
• <b>(.*)</b> matches any string enclosed within <b> and </b>.
• p(hp)* matches any string containing a p followed by zero or more
instances of the sequence hp.
Predefined Character Ranges (Character Classes)
• Several predefined character ranges, also known as character classes, are
available.
• Character classes specify an entire range of characters—for example, the
alphabet or an integer set.
• Standard classes include the following:
• [:alpha:]: Lowercase and uppercase alphabetical characters. This can also be
specified as [A-Za-z].
• [:alnum:]: Lowercase and uppercase alphabetical characters and numerical
digits. This can also be specified as [A-Za-z0-9].
• [:cntrl:]: Control characters such as tab, escape, or backspace.
• [:digit:]: Numerical digits 0 through 9. This can also be specified as [0-9].
• [:graph:]: Printable characters found in the range of ASCII 33 to 126.
• [:lower:]: Lowercase alphabetical characters. This can also be specified as [a-z].
• [:punct:]: Punctuation characters, including ~ ` ! @ # $ % ^ & * ( ) - _ + = { } [
] : ; ' < > , . ? and /.
• [:upper:]: Uppercase alphabetical characters. This can also be specified as [A-
Z].
• [:space:]: Whitespace characters, including the space, horizontal tab,
vertical tab, new line, form feed, or carriage return.
• [:xdigit:]: Hexadecimal characters. This can also be specified as [a-fA-F0-9].
Performing a Case-Sensitive Search
• The ereg() function executes a case-sensitive search of a string for a
defined pattern, returning the length of the matched string if the pattern is
found and FALSE otherwise. Its prototype follows:
• int ereg(string pattern, string string [, array regs])
Performing a Case-Insensitive Search
• The eregi() function searches a string for a defined pattern in a case-
insensitive fashion. Its prototype follows:
• int eregi(string pattern, string string, [array regs])
Replacing Text in a Case-Sensitive Fashion
• The ereg_replace() function operates much like ereg(), except that its
power is extended to finding and replacing a pattern with a replacement
string instead of simply locating it. Its prototype follows:
• string ereg_replace(string pattern, string replacement, string string)
Replacing Text in a Case-Insensitive Fashion
• The eregi_replace() function operates exactly like ereg_replace(), except
that the search for pattern in string is not case sensitive. Its prototype
follows:
• string eregi_replace(string pattern, string replacement, string string)
WRITE PHP CODE IMPLEMENTING THIS
Splitting a String into Various Elements Based
on a Case-Sensitive Pattern
• The split() function divides a string into various elements, with the
boundaries of each element based on the occurrence of a defined pattern
within the string. Its prototype follows:
• array split(string pattern, string string [, int limit])
• The optional input parameter limit is used to specify the number of
elements into which the string should be divided, starting from the left end
of the string and working rightward. In cases where the pattern is an
alphabetical character, split() is case sensitive.
Splitting a String into Various Elements Based
on a Case-Insensitive Pattern
• The spliti() function operates exactly in the same manner as its sibling,
split(), except that its pattern is treated in a case-insensitive fashion. Its
prototype follows:
• array spliti(string pattern, string string [, int limit])
WRITE PHP CODE IMPLEMENTING THIS
Accommodating Products Supporting Solely
Case-Sensitive Regular Expressions
• The sql_regcase() function converts each character in a string into a
bracketed expression containing two characters. If the character is
alphabetical, the bracket will contain both forms; otherwise, the original
character will be left unchanged. Its prototype follows:
• string sql_regcase(string string)

More Related Content

PPTX
Java: Regular Expression
PPTX
Regular expressions
PPT
16 Java Regex
PPT
Php String And Regular Expressions
PPT
Adv. python regular expression by Rj
KEY
Andrei's Regex Clinic
PPT
Regular Expression
PPTX
Specification-of-tokens
Java: Regular Expression
Regular expressions
16 Java Regex
Php String And Regular Expressions
Adv. python regular expression by Rj
Andrei's Regex Clinic
Regular Expression
Specification-of-tokens

What's hot (20)

PPT
Regular expressions
PPTX
SS UI Lecture 4
PDF
Chapter2CDpdf__2021_11_26_09_19_08.pdf
PDF
Character Array and String
PPT
PHP Regular Expressions
ODP
Looking for Patterns
PPTX
Strings in C
PPTX
Regular Expressions 101 Introduction to Regular Expressions
PDF
Regular expressions in Ruby and Introduction to Vim
PPTX
Introduction to Regular Expressions
PPTX
Chapter3pptx__2021_12_23_22_52_54.pptx
PDF
Regular expression
PPTX
Regular expressions
PPTX
Regex lecture
PPT
Strings
PDF
Regular expressions quick reference
PPTX
Strings in Python
PPT
Strings
PPT
Csharp4 strings and_regular_expressions
PDF
Strings IN C
Regular expressions
SS UI Lecture 4
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Character Array and String
PHP Regular Expressions
Looking for Patterns
Strings in C
Regular Expressions 101 Introduction to Regular Expressions
Regular expressions in Ruby and Introduction to Vim
Introduction to Regular Expressions
Chapter3pptx__2021_12_23_22_52_54.pptx
Regular expression
Regular expressions
Regex lecture
Strings
Regular expressions quick reference
Strings in Python
Strings
Csharp4 strings and_regular_expressions
Strings IN C
Ad

Similar to Regex posix (20)

PDF
FUNDAMENTALS OF REGULAR EXPRESSION (RegEX).pdf
PDF
Course 102: Lecture 13: Regular Expressions
PPT
Regular Expressions in PHP, MySQL by programmerblog.net
PDF
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
PPTX
Regular expressions in php programming language.pptx
PDF
Python - Lecture 7
PPTX
Handling of character strings C programming
PPT
Regular Expressions grep and egrep
PPTX
Regular Expressions
PPTX
unit-4 regular expression.pptx
PPTX
Bioinformatics p2-p3-perl-regexes v2014
PPTX
Python Strings.pptx
PPTX
Bioinformatica p2-p3-introduction
DOCX
Python - Regular Expressions
PPSX
Regular expressions in oracle
PDF
Lecture 10.pdf
PDF
Strings in c mrs.sowmya jyothi
PPTX
Chapter 3: Introduction to Regular Expression
PPTX
Regular Expressions here we have .pptx
PDF
Don't Fear the Regex - CapitalCamp/GovDays 2014
FUNDAMENTALS OF REGULAR EXPRESSION (RegEX).pdf
Course 102: Lecture 13: Regular Expressions
Regular Expressions in PHP, MySQL by programmerblog.net
python1uhaibueuhERADGAIUSAERUGHw9uSS.pdf
Regular expressions in php programming language.pptx
Python - Lecture 7
Handling of character strings C programming
Regular Expressions grep and egrep
Regular Expressions
unit-4 regular expression.pptx
Bioinformatics p2-p3-perl-regexes v2014
Python Strings.pptx
Bioinformatica p2-p3-introduction
Python - Regular Expressions
Regular expressions in oracle
Lecture 10.pdf
Strings in c mrs.sowmya jyothi
Chapter 3: Introduction to Regular Expression
Regular Expressions here we have .pptx
Don't Fear the Regex - CapitalCamp/GovDays 2014
Ad

More from sana mateen (20)

PPTX
PPTX
PHP Variables and scopes
PPTX
Php intro
PPTX
Php and web forms
PPTX
PPTX
Files in php
PPTX
File upload php
PPTX
Encryption in php
PPTX
Authentication methods
PPTX
Xml schema
PPTX
Xml dtd
PPTX
Xml dom
PPTX
PPTX
Intro xml
PPTX
Dom parser
PPTX
Unit 1-subroutines in perl
PPTX
Unit 1-uses for scripting languages,web scripting
PPTX
Unit 1-strings,patterns and regular expressions
PPTX
Unit 1-scalar expressions and control structures
PPTX
Unit 1-perl names values and variables
PHP Variables and scopes
Php intro
Php and web forms
Files in php
File upload php
Encryption in php
Authentication methods
Xml schema
Xml dtd
Xml dom
Intro xml
Dom parser
Unit 1-subroutines in perl
Unit 1-uses for scripting languages,web scripting
Unit 1-strings,patterns and regular expressions
Unit 1-scalar expressions and control structures
Unit 1-perl names values and variables

Recently uploaded (20)

PDF
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
PPTX
GW4 BioMed Candidate Support Webinar 2025
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
PPTX
Neurology of Systemic disease all systems
PPTX
ENGlishGrade8_Quarter2_WEEK1_LESSON1.pptx
PPTX
IT infrastructure and emerging technologies
PPTX
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
PDF
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
DOCX
EDUCATIONAL ASSESSMENT ASSIGNMENT SEMESTER MAY 2025.docx
PDF
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
PDF
GSA-Past-Papers-2010-2024-2.pdf CSS examination
PPTX
Power Point PR B.Inggris 12 Ed. 2019.pptx
PPTX
Math 2 Quarter 2 Week 1 Matatag Curriculum
PPTX
climate change of delhi impacts on climate and there effects
PPTX
Theoretical for class.pptxgshdhddhdhdhgd
PPTX
operating_systems_presentations_delhi_nc
PDF
CHALLENGES FACED BY TEACHERS WHEN TEACHING LEARNERS WITH DEVELOPMENTAL DISABI...
PPTX
CHROMIUM & Glucose Tolerance Factor.pptx
PPTX
Copy of ARAL Program Primer_071725(1).pptx
PDF
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
LATAM’s Top EdTech Innovators Transforming Learning in 2025.pdf
GW4 BioMed Candidate Support Webinar 2025
MMW-CHAPTER-1-final.pptx major Elementary Education
Neurology of Systemic disease all systems
ENGlishGrade8_Quarter2_WEEK1_LESSON1.pptx
IT infrastructure and emerging technologies
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
EDUCATIONAL ASSESSMENT ASSIGNMENT SEMESTER MAY 2025.docx
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
GSA-Past-Papers-2010-2024-2.pdf CSS examination
Power Point PR B.Inggris 12 Ed. 2019.pptx
Math 2 Quarter 2 Week 1 Matatag Curriculum
climate change of delhi impacts on climate and there effects
Theoretical for class.pptxgshdhddhdhdhgd
operating_systems_presentations_delhi_nc
CHALLENGES FACED BY TEACHERS WHEN TEACHING LEARNERS WITH DEVELOPMENTAL DISABI...
CHROMIUM & Glucose Tolerance Factor.pptx
Copy of ARAL Program Primer_071725(1).pptx
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf

Regex posix

  • 2. Brackets • Regular expressions provide the foundation for describing or matching data according to defined syntax rules. • There are three methods that POSIX supports for locating different character sequences: brackets, quantifiers, and predefined character ranges. • Brackets ([]) are used to represent a list, or range, of characters to be matched. • For instance, the regular expression [php] will find any string containing the character p or h. Several commonly used character ranges follow: • [0-9] matches any decimal digit from 0 through 9. • [a-z] matches any character from lowercase a through lowercase z. • [A-Z] matches any character from uppercase A through uppercase Z. • [A-Za-z] matches any character from uppercase A through lowercase z.
  • 3. Quantifiers • Here are several examples of these characters: • p+ matches any string containing at least one p. • p* matches any string containing zero or more p’s. • p? matches any string containing zero or one p. • p{2} matches any string containing a sequence of two p’s. • p{2,3} matches any string containing a sequence of two or three p’s. • p{2,} matches any string containing a sequence of at least two p’s. • p$ matches any string with p at the end of it. • Still other flags can be inserted before and within a character sequence: • ^p matches any string with p at the beginning of it. • [^a-zA-Z] matches any string not containing any of the characters ranging from a through z and A through Z. • p.p matches any string containing p, followed by any character, in turn followed by another p. • You can also combine special characters to form more complex expressions. Consider the following examples: • ^.{2}$ matches any string containing exactly two characters. • <b>(.*)</b> matches any string enclosed within <b> and </b>. • p(hp)* matches any string containing a p followed by zero or more instances of the sequence hp.
  • 4. Predefined Character Ranges (Character Classes) • Several predefined character ranges, also known as character classes, are available. • Character classes specify an entire range of characters—for example, the alphabet or an integer set. • Standard classes include the following: • [:alpha:]: Lowercase and uppercase alphabetical characters. This can also be specified as [A-Za-z]. • [:alnum:]: Lowercase and uppercase alphabetical characters and numerical digits. This can also be specified as [A-Za-z0-9]. • [:cntrl:]: Control characters such as tab, escape, or backspace. • [:digit:]: Numerical digits 0 through 9. This can also be specified as [0-9]. • [:graph:]: Printable characters found in the range of ASCII 33 to 126. • [:lower:]: Lowercase alphabetical characters. This can also be specified as [a-z]. • [:punct:]: Punctuation characters, including ~ ` ! @ # $ % ^ & * ( ) - _ + = { } [ ] : ; ' < > , . ? and /. • [:upper:]: Uppercase alphabetical characters. This can also be specified as [A- Z]. • [:space:]: Whitespace characters, including the space, horizontal tab, vertical tab, new line, form feed, or carriage return. • [:xdigit:]: Hexadecimal characters. This can also be specified as [a-fA-F0-9].
  • 5. Performing a Case-Sensitive Search • The ereg() function executes a case-sensitive search of a string for a defined pattern, returning the length of the matched string if the pattern is found and FALSE otherwise. Its prototype follows: • int ereg(string pattern, string string [, array regs])
  • 6. Performing a Case-Insensitive Search • The eregi() function searches a string for a defined pattern in a case- insensitive fashion. Its prototype follows: • int eregi(string pattern, string string, [array regs])
  • 7. Replacing Text in a Case-Sensitive Fashion • The ereg_replace() function operates much like ereg(), except that its power is extended to finding and replacing a pattern with a replacement string instead of simply locating it. Its prototype follows: • string ereg_replace(string pattern, string replacement, string string)
  • 8. Replacing Text in a Case-Insensitive Fashion • The eregi_replace() function operates exactly like ereg_replace(), except that the search for pattern in string is not case sensitive. Its prototype follows: • string eregi_replace(string pattern, string replacement, string string) WRITE PHP CODE IMPLEMENTING THIS
  • 9. Splitting a String into Various Elements Based on a Case-Sensitive Pattern • The split() function divides a string into various elements, with the boundaries of each element based on the occurrence of a defined pattern within the string. Its prototype follows: • array split(string pattern, string string [, int limit]) • The optional input parameter limit is used to specify the number of elements into which the string should be divided, starting from the left end of the string and working rightward. In cases where the pattern is an alphabetical character, split() is case sensitive.
  • 10. Splitting a String into Various Elements Based on a Case-Insensitive Pattern • The spliti() function operates exactly in the same manner as its sibling, split(), except that its pattern is treated in a case-insensitive fashion. Its prototype follows: • array spliti(string pattern, string string [, int limit]) WRITE PHP CODE IMPLEMENTING THIS
  • 11. Accommodating Products Supporting Solely Case-Sensitive Regular Expressions • The sql_regcase() function converts each character in a string into a bracketed expression containing two characters. If the character is alphabetical, the bracket will contain both forms; otherwise, the original character will be left unchanged. Its prototype follows: • string sql_regcase(string string)