SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
And are they contagious?
There is no official standard for
regular expressions, so no real
definition.

Simply put, you can call it a
text pattern to search and/or
                                    Easy peasy!
replace text.
Perl programming language



Perl-compatible

.NET

Java

JavaScript

…
                  What, no cherry flavour?
Back to grammar school!
a matches any occurrence of that character

Jack is a boy.

cat matches

About cats and dogs.
square bracket                [
backslash                     
caret                         ^
dollar sign                   $
period or dot                 .
vertical bar or pipe symbol   |
question mark                 ?
asterisk or star              *
plus sign                     +
opening round bracket         (
closing round bracket         )
opening curley bracket        {
Special characters are reserved for special use.

They need to be preceded by a backslash if you want to
match them as literal characters.

This is called escaping.

If you want to match 1+1=2 the correct regex is 1+1=2
tab                 t
carriage return     r
line feed           n


beginning of line   ^
end of line         $
word boundary       b
If regular expressions are Unicode enabled you can
search any character using the Unicode value.

Depending on syntax: u0000 or x{0000}

Hard space             u00A0 or x{00A0}
® sign                 u00AE or x{00AE}
...
Quantifiers allow you to specify the number of
occurrences to match against

X?             X, once or not at all
X*             X, zero or more times
X+             X, one or more times
X{n}           X, exactly n times
X{n,}          X, at least n times
X{n,m}         X, at least n but not more than m times
The regex colou?r matches both colour and color.

You can also group items together by using brackets:

Nov(ember)? will match Nov and November

The regex a+ is the same as a{1,} and matches a or aaaaa

The regex w{3} matches www.qa-distiller.com
Simply place the characters you want to match between
square brackets.

If you want to match an a or an e, use [ae]. You could
use this in gr[ae]y to match either gray or grey.

A character class matches only a single character, the
order is not important

You can also use ranges. [0-9] matches a single digit
between 0 and 9
Typing a caret after the opening square bracket will negate
the character class.

q[^u] means: "a q followed by a character that is not a u".

It will match the q and the space after the q in

Iraq is a political quagmire.

but not the q of quagmire because it is followed by the
letter u
d             digit                  [0-9]
w             word character         [A-Za-z0-9_ ]
s             whitespace             [ trn]

Negated versions

D             not a digit            [^d]
W             not a word character   [^w]
S             not a whitespace       [^s]
The dot matches a single character, without caring what
that character is.

The regex e. matches

Houston, we have a problem
If you want to search for cat or dog, separate both options
with a vertical bar or pipe symbol:

cat|dog matches

Are you sure you want a cat?

You can add more options like this:

green|black|yellow|white
Which of the following completely matches regex a(ab)*a

1)   abababa
2)   aaba
3)   aabbaa
4)   aba
5)   aabababa
Which of the following completely matches regex ab+c?

1)   abc
2)   ac
3)   abbb
4)   bbc
5)   abbcc
Which of the following completely matches regex a.[bc]+

1)   abc
2)   abbbbbbbb
3)   azc
4)   abcbcbcbc
5)   ac
6)   asccbbbbcbcccc
Which of the following completely matches regex
(very )+(fat )?(tall|ugly) man

1)   very fat man
2)   fat tall man
3)   very very fat ugly man
4)   very very very tall man
Still awake?
Positive lookahead:           X(?=X)

Match something that is followed by something
Yamagata(?= Europe) matches

Yamagata Europe, Yamagata Intech Solutions

Negative lookahead:           X(?!X)

Match something that is not followed by something
Yamagata(?! Europe) matches

Yamagata Europe, Yamagata Intech Solutions
Positive lookbehind:         (?<=X)X

Match something following something
(?<=a)b matches

thingamabob

Negative lookbehind:         (?<!X)X

Match something not following something
(?<!a)b matches

thingamabob
Round brackets create a backreference.

You can use the backreference with a backslash + the number of the
backreference.

The regex Java(script) is a 1ing language matches
Javascript is a scripting language

The regex (Java)(script) is a 2ing language that is not the same as 1
matches
Javascript is a scripting language that is not the same as Java
Use the regex b(w+) 1b to find doubled words.

Ze streelde haar haar in in de auto.

With exceptions:

b(?!haarb)(w+) 1b

Ze streelde haar haar in in de auto.
You want to add brackets around step numbers:

This is step 5 from chapter 1. Continue with step 45 from page 15.

Use the regex ([sS]tep) (d+) to find all instances.

Replace it by 1 (2)

Or alternatively (?<=[sS]tep )d+ by (0)
Powerful, for individual text-based files


More powerful, batch operations, command line


No back references


RegEx Text File Filter


RegEx search


Very limited


Powerful, called GREP
Some people, when confronted with a problem, think
"I know, I'll use regular expressions.“
Now they have two problems.


-> Do not try to do everything in one uber-regex
-> Regular expressions are not parsers
http://www.regular-expressions.info

Weitere ähnliche Inhalte

Was ist angesagt?

Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsDanny Bryant
 
katagaitai workshop #7 crypto ナップサック暗号と低密度攻撃
katagaitai workshop #7 crypto ナップサック暗号と低密度攻撃katagaitai workshop #7 crypto ナップサック暗号と低密度攻撃
katagaitai workshop #7 crypto ナップサック暗号と低密度攻撃trmr
 
パタヘネゼミ 第6章
パタヘネゼミ 第6章パタヘネゼミ 第6章
パタヘネゼミ 第6章okuraofvegetable
 
WASM(WebAssembly)入門 ペアリング演算やってみた
WASM(WebAssembly)入門 ペアリング演算やってみたWASM(WebAssembly)入門 ペアリング演算やってみた
WASM(WebAssembly)入門 ペアリング演算やってみたMITSUNARI Shigeo
 
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...Philip Schwarz
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQLCommand Prompt., Inc
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.pptRatnakar Mikkili
 
公開鍵暗号8: 有限体上の楕円曲線の位数計算
公開鍵暗号8: 有限体上の楕円曲線の位数計算公開鍵暗号8: 有限体上の楕円曲線の位数計算
公開鍵暗号8: 有限体上の楕円曲線の位数計算Joe Suzuki
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesArun Gupta
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesEelco Visser
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal formsAkila Krishnamoorthy
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expressionvaluebound
 
V8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパーV8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパーTaketoshi 青野健利
 
Beyond unit tests: Testing for Spark/Hadoop Workflows with Shankar Manian Ana...
Beyond unit tests: Testing for Spark/Hadoop Workflows with Shankar Manian Ana...Beyond unit tests: Testing for Spark/Hadoop Workflows with Shankar Manian Ana...
Beyond unit tests: Testing for Spark/Hadoop Workflows with Shankar Manian Ana...Spark Summit
 
Hadoop & Big Data benchmarking
Hadoop & Big Data benchmarkingHadoop & Big Data benchmarking
Hadoop & Big Data benchmarkingBart Vandewoestyne
 

Was ist angesagt? (20)

Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular Expressions
 
katagaitai workshop #7 crypto ナップサック暗号と低密度攻撃
katagaitai workshop #7 crypto ナップサック暗号と低密度攻撃katagaitai workshop #7 crypto ナップサック暗号と低密度攻撃
katagaitai workshop #7 crypto ナップサック暗号と低密度攻撃
 
Sql Antipatterns Strike Back
Sql Antipatterns Strike BackSql Antipatterns Strike Back
Sql Antipatterns Strike Back
 
パタヘネゼミ 第6章
パタヘネゼミ 第6章パタヘネゼミ 第6章
パタヘネゼミ 第6章
 
WASM(WebAssembly)入門 ペアリング演算やってみた
WASM(WebAssembly)入門 ペアリング演算やってみたWASM(WebAssembly)入門 ペアリング演算やってみた
WASM(WebAssembly)入門 ペアリング演算やってみた
 
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...Algebraic Data Types forData Oriented Programming - From Haskell and Scala t...
Algebraic Data Types for Data Oriented Programming - From Haskell and Scala t...
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQL
 
2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt2_2Specification of Tokens.ppt
2_2Specification of Tokens.ppt
 
公開鍵暗号8: 有限体上の楕円曲線の位数計算
公開鍵暗号8: 有限体上の楕円曲線の位数計算公開鍵暗号8: 有限体上の楕円曲線の位数計算
公開鍵暗号8: 有限体上の楕円曲線の位数計算
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and Scopes
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
V8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパーV8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパー
 
C# in depth
C# in depthC# in depth
C# in depth
 
07 java collection
07 java collection07 java collection
07 java collection
 
Beyond unit tests: Testing for Spark/Hadoop Workflows with Shankar Manian Ana...
Beyond unit tests: Testing for Spark/Hadoop Workflows with Shankar Manian Ana...Beyond unit tests: Testing for Spark/Hadoop Workflows with Shankar Manian Ana...
Beyond unit tests: Testing for Spark/Hadoop Workflows with Shankar Manian Ana...
 
Hadoop & Big Data benchmarking
Hadoop & Big Data benchmarkingHadoop & Big Data benchmarking
Hadoop & Big Data benchmarking
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 

Ähnlich wie An Introduction to Regular expressions

Ähnlich wie An Introduction to Regular expressions (20)

Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular expressions quick reference
Regular expressions quick referenceRegular expressions quick reference
Regular expressions quick reference
 
Regex Intro
Regex IntroRegex Intro
Regex Intro
 
Regex Basics
Regex BasicsRegex Basics
Regex Basics
 
Eloquent Ruby chapter 4 - Find The Right String with Regular Expression
Eloquent Ruby chapter 4 - Find The Right String with Regular ExpressionEloquent Ruby chapter 4 - Find The Right String with Regular Expression
Eloquent Ruby chapter 4 - Find The Right String with Regular Expression
 
Regexps
RegexpsRegexps
Regexps
 
Looking for Patterns
Looking for PatternsLooking for Patterns
Looking for Patterns
 
Expresiones Regulares
Expresiones RegularesExpresiones Regulares
Expresiones Regulares
 
FUNDAMENTALS OF REGULAR EXPRESSION (RegEX).pdf
FUNDAMENTALS OF REGULAR EXPRESSION (RegEX).pdfFUNDAMENTALS OF REGULAR EXPRESSION (RegEX).pdf
FUNDAMENTALS OF REGULAR EXPRESSION (RegEX).pdf
 
Python (regular expression)
Python (regular expression)Python (regular expression)
Python (regular expression)
 
test vedio
test vediotest vedio
test vedio
 
qwdeqwe
qwdeqweqwdeqwe
qwdeqwe
 
Added to test pdf
Added to test pdf Added to test pdf
Added to test pdf
 
added for test
added for test added for test
added for test
 
ganesh testing
ganesh testing ganesh testing
ganesh testing
 
now its pdf
now its pdfnow its pdf
now its pdf
 
fghfghf
fghfghffghfghf
fghfghf
 
The hindu
The hinduThe hindu
The hindu
 
Video added by Normal user
Video added by Normal user Video added by Normal user
Video added by Normal user
 
Resource one
Resource one Resource one
Resource one
 

Mehr von Yamagata Europe

Machine Translation Quality Metrics
Machine Translation Quality MetricsMachine Translation Quality Metrics
Machine Translation Quality MetricsYamagata Europe
 
A standards driven workflow for Sitecore localization
A standards driven workflow for Sitecore localizationA standards driven workflow for Sitecore localization
A standards driven workflow for Sitecore localizationYamagata Europe
 
DITA translatability best practices
DITA translatability best practicesDITA translatability best practices
DITA translatability best practicesYamagata Europe
 

Mehr von Yamagata Europe (8)

Smart QA
Smart QASmart QA
Smart QA
 
Machine Translation Quality Metrics
Machine Translation Quality MetricsMachine Translation Quality Metrics
Machine Translation Quality Metrics
 
XML and Localization
XML and LocalizationXML and Localization
XML and Localization
 
A standards driven workflow for Sitecore localization
A standards driven workflow for Sitecore localizationA standards driven workflow for Sitecore localization
A standards driven workflow for Sitecore localization
 
QA Distiller
QA DistillerQA Distiller
QA Distiller
 
SnellSpell
SnellSpellSnellSpell
SnellSpell
 
Machine translation
Machine translationMachine translation
Machine translation
 
DITA translatability best practices
DITA translatability best practicesDITA translatability best practices
DITA translatability best practices
 

Kürzlich hochgeladen

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

An Introduction to Regular expressions

  • 1.
  • 2. And are they contagious?
  • 3. There is no official standard for regular expressions, so no real definition. Simply put, you can call it a text pattern to search and/or Easy peasy! replace text.
  • 5. Back to grammar school!
  • 6. a matches any occurrence of that character Jack is a boy. cat matches About cats and dogs.
  • 7. square bracket [ backslash caret ^ dollar sign $ period or dot . vertical bar or pipe symbol | question mark ? asterisk or star * plus sign + opening round bracket ( closing round bracket ) opening curley bracket {
  • 8. Special characters are reserved for special use. They need to be preceded by a backslash if you want to match them as literal characters. This is called escaping. If you want to match 1+1=2 the correct regex is 1+1=2
  • 9. tab t carriage return r line feed n beginning of line ^ end of line $ word boundary b
  • 10. If regular expressions are Unicode enabled you can search any character using the Unicode value. Depending on syntax: u0000 or x{0000} Hard space u00A0 or x{00A0} ® sign u00AE or x{00AE} ...
  • 11. Quantifiers allow you to specify the number of occurrences to match against X? X, once or not at all X* X, zero or more times X+ X, one or more times X{n} X, exactly n times X{n,} X, at least n times X{n,m} X, at least n but not more than m times
  • 12. The regex colou?r matches both colour and color. You can also group items together by using brackets: Nov(ember)? will match Nov and November The regex a+ is the same as a{1,} and matches a or aaaaa The regex w{3} matches www.qa-distiller.com
  • 13. Simply place the characters you want to match between square brackets. If you want to match an a or an e, use [ae]. You could use this in gr[ae]y to match either gray or grey. A character class matches only a single character, the order is not important You can also use ranges. [0-9] matches a single digit between 0 and 9
  • 14. Typing a caret after the opening square bracket will negate the character class. q[^u] means: "a q followed by a character that is not a u". It will match the q and the space after the q in Iraq is a political quagmire. but not the q of quagmire because it is followed by the letter u
  • 15. d digit [0-9] w word character [A-Za-z0-9_ ] s whitespace [ trn] Negated versions D not a digit [^d] W not a word character [^w] S not a whitespace [^s]
  • 16. The dot matches a single character, without caring what that character is. The regex e. matches Houston, we have a problem
  • 17. If you want to search for cat or dog, separate both options with a vertical bar or pipe symbol: cat|dog matches Are you sure you want a cat? You can add more options like this: green|black|yellow|white
  • 18. Which of the following completely matches regex a(ab)*a 1) abababa 2) aaba 3) aabbaa 4) aba 5) aabababa
  • 19. Which of the following completely matches regex ab+c? 1) abc 2) ac 3) abbb 4) bbc 5) abbcc
  • 20. Which of the following completely matches regex a.[bc]+ 1) abc 2) abbbbbbbb 3) azc 4) abcbcbcbc 5) ac 6) asccbbbbcbcccc
  • 21. Which of the following completely matches regex (very )+(fat )?(tall|ugly) man 1) very fat man 2) fat tall man 3) very very fat ugly man 4) very very very tall man
  • 23. Positive lookahead: X(?=X) Match something that is followed by something Yamagata(?= Europe) matches Yamagata Europe, Yamagata Intech Solutions Negative lookahead: X(?!X) Match something that is not followed by something Yamagata(?! Europe) matches Yamagata Europe, Yamagata Intech Solutions
  • 24. Positive lookbehind: (?<=X)X Match something following something (?<=a)b matches thingamabob Negative lookbehind: (?<!X)X Match something not following something (?<!a)b matches thingamabob
  • 25. Round brackets create a backreference. You can use the backreference with a backslash + the number of the backreference. The regex Java(script) is a 1ing language matches Javascript is a scripting language The regex (Java)(script) is a 2ing language that is not the same as 1 matches Javascript is a scripting language that is not the same as Java
  • 26. Use the regex b(w+) 1b to find doubled words. Ze streelde haar haar in in de auto. With exceptions: b(?!haarb)(w+) 1b Ze streelde haar haar in in de auto.
  • 27. You want to add brackets around step numbers: This is step 5 from chapter 1. Continue with step 45 from page 15. Use the regex ([sS]tep) (d+) to find all instances. Replace it by 1 (2) Or alternatively (?<=[sS]tep )d+ by (0)
  • 28. Powerful, for individual text-based files More powerful, batch operations, command line No back references RegEx Text File Filter RegEx search Very limited Powerful, called GREP
  • 29. Some people, when confronted with a problem, think "I know, I'll use regular expressions.“ Now they have two problems. -> Do not try to do everything in one uber-regex -> Regular expressions are not parsers