SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Beginner Track: Introduction to Regular Expressions (aka “regex”) Bil Corry lasso.pro
What is regex? “ Regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters.” ( Wikipedia: http://en.wikipedia.org/wiki/Regex) In plain English: Regex is a text-searching “language.”
How regex works Three components are needed: ,[object Object]
Some text to search against
A regular expression that defines what to search for (e.g. “” to find a digit)
#1 Regex Engine ,[object Object]
[string_replaceregexp]
[regexp]
[compare_regexp]
[compare_notregexp]
[match_regexp]
[match_notregexp]
#2 Some Text To Search Against ,[object Object]
There may be performance and memory challenges using regex against a sizably large [string]
#3 Regular Expressions: The regex “language” ,[object Object]
Dot
White Space
Character Classes
Shorthand Character Classes ,[object Object]
Alternation
Quantifiers
Grouping
Literals All characters search for their literal selves except for the following: “ [$.|?*+()” – they require being escaped when searched for as a literal. Example: [string_findregexp('LDC is fun!',-find='fun')] LP8:  array: (fun) L9:  array(fun)
Literals (cont) By default, regex is case-sensitive.  Use the (?i) switch to make it case-insensitive. Examples: [string_findregexp('ABC abc',-find='abc')] LP8:  array: (abc) L9:  array(abc) [string_findregexp('ABC abc',-find='(?i)abc')] LP8:  array: (ABC), (abc) L9:  array(ABC, abc)
Escaping Characters In regular expressions, depending on the context, various characters have special meaning.  In order to specify the literal character, you must escape it with a backslash (“).  And because the backslash has special meaning in Lasso, it means you must double the backslashes in Lasso (“”).
Escaping Characters (cont) Example: [string_findregexp('[date] returns the date', -find='[date]')] LP8:  array: ([date]) L9:  array([date]) [string_findregexp('[date] returns the date', -find='[date]')] LP8: array:(d),(a),(t),(e),(e),(t),(t),(e),(d),(a),(t),(e) L9: array(d, a, t, e, e, t, t, e, d, a, t, e)
Dot A dot (aka period symbol “.”) will match any single character except line returns.  Use the switch “(?s)” to turn on matching line returns too. Example: [string_findregexp('LDC is fun! Turn on a fan.', -find='f.n')] LP8:  array: (fun), (fan) L9:  array(fun, fan)
Dot (cont) [string_findregexp('123',-find='.')] LP8: array: (1), (2), (3) L9:  array(1, 2, 3) [string_findregexp('123',-find='(?s).')] LP8: array: (1), ( ), (2), ( ), (3) L9:  array(1, , 2, , 3)
White Space To find white space, use the Lasso equivalents: Return =  Newline =  Tab =  Example: [string_findregexp('123',-find='')] LP8:  array: ( ), ( ) L9:  array( , )
Character Classes Used to match against a set of characters contained within square brackets “[ … ]”.  Order of characters within the class does not matter (i.e. [abc] == [cba]).  Reserved characters are  “ ^-]. Example: [string_findregexp('New Years Eve is 2009-12-31', -find='[123ae]')] LP8:array: (e), (e), (a), (e), (2), (1), (2), (3), (1) L9: array(e, e, a, e, 2, 1, 2, 3, 1)
Character Classes (cont) Hyphen denotes a range (e.g. “[0-9]” means 0,1,2,..,9 and [a-z] means a,b,c,...,z). Example: [string_findregexp('abcdef',-find='[b-d]')] LP8:  array: (b), (c), (d) L9:  array(b, c, d)

Weitere ähnliche Inhalte

Was ist angesagt?

Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular ExpressionsOCSI
 
Python (regular expression)
Python (regular expression)Python (regular expression)
Python (regular expression)Chirag Shetty
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular ExpressionsJesse Anderson
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsBrij Kishore
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regexJalpesh Vasa
 
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
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashessana mateen
 
Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Bryan O'Sullivan
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Andrea Telatin
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressionsBen Brumfield
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expressionGagan019
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and YouJames Armes
 
Basta mastering regex power
Basta mastering regex powerBasta mastering regex power
Basta mastering regex powerMax Kleiner
 
Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Ben Brumfield
 
Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1andreas_schultz
 

Was ist angesagt? (20)

Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
 
Python (regular expression)
Python (regular expression)Python (regular expression)
Python (regular expression)
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
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
 
Python : Regular expressions
Python : Regular expressionsPython : Regular expressions
Python : Regular expressions
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashes
 
Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
2.regular expressions
2.regular expressions2.regular expressions
2.regular expressions
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and You
 
Basta mastering regex power
Basta mastering regex powerBasta mastering regex power
Basta mastering regex power
 
Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013
 
Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1
 

Ähnlich wie Introduction To Regex in Lasso 8.5

Regular expressions
Regular expressionsRegular expressions
Regular expressionsEran Zimbler
 
Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Ahmed El-Arabawy
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionskeeyre
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressionsmussawir20
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20Max Kleiner
 
Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionProf. Wim Van Criekinge
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007Geoffrey Dunn
 
Regex startup
Regex startupRegex startup
Regex startupPayPal
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressionsKrishna Nanda
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
New features in abap
New features in abapNew features in abap
New features in abapSrihari J
 
Introduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_RIntroduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_RHellen Gakuruh
 
Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009David Pollak
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracleLogan Palanisamy
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlsana mateen
 

Ähnlich wie Introduction To Regex in Lasso 8.5 (20)

Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
 
Les08
Les08Les08
Les08
 
Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introduction
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007
 
Regex startup
Regex startupRegex startup
Regex startup
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
RegEx Book.pdf
RegEx Book.pdfRegEx Book.pdf
RegEx Book.pdf
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regex lecture
Regex lectureRegex lecture
Regex lecture
 
New features in abap
New features in abapNew features in abap
New features in abap
 
Introduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_RIntroduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_R
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Quick start reg ex
Quick start reg exQuick start reg ex
Quick start reg ex
 
Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 

Kürzlich hochgeladen

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Kürzlich hochgeladen (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Introduction To Regex in Lasso 8.5

  • 1. Beginner Track: Introduction to Regular Expressions (aka “regex”) Bil Corry lasso.pro
  • 2. What is regex? “ Regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters.” ( Wikipedia: http://en.wikipedia.org/wiki/Regex) In plain English: Regex is a text-searching “language.”
  • 3.
  • 4. Some text to search against
  • 5. A regular expression that defines what to search for (e.g. “” to find a digit)
  • 6.
  • 13.
  • 14. There may be performance and memory challenges using regex against a sizably large [string]
  • 15.
  • 16. Dot
  • 19.
  • 23. Literals All characters search for their literal selves except for the following: “ [$.|?*+()” – they require being escaped when searched for as a literal. Example: [string_findregexp('LDC is fun!',-find='fun')] LP8: array: (fun) L9: array(fun)
  • 24. Literals (cont) By default, regex is case-sensitive. Use the (?i) switch to make it case-insensitive. Examples: [string_findregexp('ABC abc',-find='abc')] LP8: array: (abc) L9: array(abc) [string_findregexp('ABC abc',-find='(?i)abc')] LP8: array: (ABC), (abc) L9: array(ABC, abc)
  • 25. Escaping Characters In regular expressions, depending on the context, various characters have special meaning. In order to specify the literal character, you must escape it with a backslash (“). And because the backslash has special meaning in Lasso, it means you must double the backslashes in Lasso (“”).
  • 26. Escaping Characters (cont) Example: [string_findregexp('[date] returns the date', -find='[date]')] LP8: array: ([date]) L9: array([date]) [string_findregexp('[date] returns the date', -find='[date]')] LP8: array:(d),(a),(t),(e),(e),(t),(t),(e),(d),(a),(t),(e) L9: array(d, a, t, e, e, t, t, e, d, a, t, e)
  • 27. Dot A dot (aka period symbol “.”) will match any single character except line returns. Use the switch “(?s)” to turn on matching line returns too. Example: [string_findregexp('LDC is fun! Turn on a fan.', -find='f.n')] LP8: array: (fun), (fan) L9: array(fun, fan)
  • 28. Dot (cont) [string_findregexp('123',-find='.')] LP8: array: (1), (2), (3) L9: array(1, 2, 3) [string_findregexp('123',-find='(?s).')] LP8: array: (1), ( ), (2), ( ), (3) L9: array(1, , 2, , 3)
  • 29. White Space To find white space, use the Lasso equivalents: Return = Newline = Tab = Example: [string_findregexp('123',-find='')] LP8: array: ( ), ( ) L9: array( , )
  • 30. Character Classes Used to match against a set of characters contained within square brackets “[ … ]”. Order of characters within the class does not matter (i.e. [abc] == [cba]). Reserved characters are “ ^-]. Example: [string_findregexp('New Years Eve is 2009-12-31', -find='[123ae]')] LP8:array: (e), (e), (a), (e), (2), (1), (2), (3), (1) L9: array(e, e, a, e, 2, 1, 2, 3, 1)
  • 31. Character Classes (cont) Hyphen denotes a range (e.g. “[0-9]” means 0,1,2,..,9 and [a-z] means a,b,c,...,z). Example: [string_findregexp('abcdef',-find='[b-d]')] LP8: array: (b), (c), (d) L9: array(b, c, d)
  • 32. Character Classes (cont) A caret after the opening square bracket denotes characters to omit instead of find. Example: [string_findregexp('abcdef',-find='[^b-d]')] LP8: array: (a), (e), (f) L9: array(a, e, f)
  • 33. Shorthand Character Classes d = [0-9] D = [^0-9] w ≈ [a-zA-Z0-9_] W ≈ [^a-zA-Z0-9_] s ≈ [] S ≈ [^] Example: [string_findregexp('1a2b3c',-find='d')] LP8: array: (1), (2), (3) L9: array(1, 2, 3) [string_findregexp('1a2b3c',-find='D')] LP8: array: (a), (b), (c) L9: array(a, b, c)
  • 34. Shorthand Character Classes (cont) Example: [string_findregexp('1a2b3c',-find='w')] LP8: array: (1), (a), (2), (b), (3), (c) L9: array(1, a, 2, b, 3, c) [string_findregexp('123',-find='s')] LP8: array: ( ), ( ) L9: array( , )
  • 35. Positional Matching “^” matches beginning of text, “$” matches end of text, and (?m) switch makes ^ and $ match beginning and ending of each line. Example: [string_findregexp('123',-find='^d')] LP8: array: (1) L9: array(1) [string_findregexp('123',-find='(?m)^d')] LP8: array: (1), (2), (3) L9: array(1, 2, 3)
  • 36. Positional Matching (cont) “b” matches a word boundary (the position between a word character and a non-word character or start/end of line). Example: [string_findregexp('cape and ape',-find='bape')] LP8: array: (ape) L9: array(ape) [string_findregexp('cape and ape',-find='ape')] LP8: array: (ape), (ape) L9: array(ape, ape)
  • 37. Alternation Vertical bar (“|”) is an OR operand for regex. Example: [string_findregexp('cat and rat',-find='cat|rat')] LP8: array: (cat), (rat) L9: array(cat, rat)
  • 38. Quantifiers Specifies the number to find: * = 0 or more + = 1 or more ? = 0 or 1 {n} = n times {n,m} = min n, max m times {n, } = min n, no max Example: [string_findregexp('123aaabbb', -find='0*1+2?3{1}a{1,2}ab{2,}')] LP8: array: (123aaabbb) L9: array(123aaabbb)
  • 39. Grouping Round brackets “( )” group the regex together, allowing quantifiers to be used on the group or to perform AND/OR with regex. They also create backreferences, which we won't cover in this session, but know that Lasso returns the group match in addition to the overall match. Example: [string_findregexp('cat and rat',-find='(c|r)at')] LP8: array: (cat), (c), (rat), (r) L9: array(cat, c, rat, r)
  • 40. Grouping (cont) There is an option for non-capturing groups: “(?: … regex here...)” Example: [string_findregexp('cat and rat',-find='(?:c|r)at')] LP8: array: (cat), (rat) L9: array(cat, rat)
  • 41.
  • 42. When using regular expressions obtained from outside sources, you'll need to double-up the backslashes (“) for Lasso (e.g. “+” becomes “d+”).
  • 43. User-input used as part of a regular expression must be encoded (http://tagswap.net/lp_regexp_encode)
  • 44.
  • 45. Often, there are several ways to match. If one approach doesn't work, try another.
  • 46. Great reference and tutorial site: www.regular-expressions.info
  • 47. Examples Extract names from comma-delimited list: [string_findregexp('Abe Smith, Bob Jones, Cindy Hart, Darla King',-find='w+s+w+')] LP8: array: (Abe Smith), (Bob Jones), (Cindy Hart), (Darla King) L9: array(Abe Smith, Bob Jones, Cindy Hart, Darla King)
  • 48. Examples (cont) Extract phone numbers into a packed format: [string_findregexp('(213) 555-1212',-find='d') ->join('')] [string_findregexp('213-555-1212',-find='d') ->join('')] [string_findregexp('213 555 1212',-find='d') ->join('')] LP8: 2135551212 2135551212 2135551212 L9: 2135551212 2135551212 2135551212
  • 49. Examples (cont) Extract data from HTML: [string_findregexp('<input type=&quot;hidden&quot; name=&quot;secret&quot; value=&quot;123&quot;>',-find='name=&quot;secret&quot; value=&quot;[^&quot;]+')] LP8: array: (name=&quot;secret&quot; value=&quot;123) L9: array(name=&quot;secret&quot; value=&quot;123) [string_findregexp('<input type=&quot;hidden&quot; name=&quot;secret&quot; value=&quot;123&quot;>',-find='name=&quot;secret&quot; value=&quot;([^&quot;]+)')] LP8: array: (name=&quot;secret&quot; value=&quot;123), (123) L9: array(name=&quot;secret&quot; value=&quot;123, 123)
  • 50. Examples (cont) Extract data from HTML: [string_findregexp('<input type=&quot;hidden&quot; name=&quot;secret&quot; value=&quot;123&quot;>',-find='(?:name=&quot;secret&quot; value=&quot;)[^&quot;]+')] LP8: array: (name=&quot;secret&quot; value=&quot;123) L9: array(name=&quot;secret&quot; value=&quot;123) [string_findregexp('<input type=&quot;hidden&quot; name=&quot;secret&quot; value=&quot;123&quot;>',-find='(?<=name=&quot;secret&quot; value=&quot;)[^&quot;]+')] LP8: array: (123) L9: array(123)