Regular Expressions BKF03 Brian Ciccolo. Agenda Definition Uses – within Aspen and beyond Matching Replacing.

Slides:



Advertisements
Similar presentations
Session 3BBK P1 ModuleApril 2010 : [#] Regular Expressions.
Advertisements

Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
BBK P1 Module2010/11 : [‹#›] Regular Expressions.
2-1. Today’s Lecture Review Chapter 4 Go over exercises.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Tutorial 6 Creating a Web Form
Python: Regular Expressions
PERL Part 3 1.Subroutines 2.Pattern matching and regular expressions.
Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl Linux editors and commands (e.g.
Regex Wildcards on steroids. Regular Expressions You’ve likely used the wildcard in windows search or coding (*), regular expressions take this to the.
Regular Expressions. String Matching The problem of finding a string that “looks kind of like …” is common  e.g. finding useful delimiters in a file,
REGULAR EXPRESSIONS CHAPTER 14. REGULAR EXPRESSIONS A coded pattern used to search for matching patterns in text strings Commonly used for data validation.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Last Updated March 2006 Slide 1 Regular Expressions.
Regular Expressions Week 07 TCNJ Web 2 Jean Chu. Regular Expressions Regular Expressions are a powerful way to validate and format text strings that may.
PHP Workshop ‹#› Data Manipulation & Regex. PHP Workshop ‹#› What..? Often in PHP we have to get data from files, or maybe through forms from a user.
Using Regular Expressions in Java for Data Validation Evelyn Brannock Jan 30, 2009.
Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital Media.
 A database is a collection of data that is organized so that its contents can easily be accessed, managed, and updated. What is Database?
CIS 451: Regular Expressions Dr. Ralph D. Westfall January, 2009.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Perl and Regular Expressions Regular Expressions are available as part of the programming languages Java, JScript, Visual Basic and VBScript, JavaScript,
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Python Regular Expressions Easy text processing. Regular Expression  A way of identifying certain String patterns  Formally, a RE is:  a letter or.
1 CSC 594 Topics in AI – Text Mining and Analytics Fall 2015/16 4. Document Search and Regular Expressions.
Regular Expressions CSC207 – Software Design. Motivation Handling white space –A program ought to be able to treat any number of white space characters.
Regular Expressions.
Regular Expression Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
BY Sandeep Kumar Gampa.. What is Regular Expression? Regex in.NET Regex Language Elements Examples Regular Expression API How to Test regex in.NET Conclusion.
Regular Expressions in PHP. Supported RE’s The most important set of regex functions start with preg. These functions are a PHP wrapper around the PCRE.
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
Regular Expressions. Overview Regular expressions allow you to do complex searches within text documents. Examples: Search 8-K filings for restatements.
Module 6 – Generics Module 7 – Regular Expressions.
Regular Expressions for PHP Adding magic to your programming. Geoffrey Dunn
Satisfy Your Technical Curiosity Regular Expressions Roy Osherove Methodology & Team System Expert Sela Group The.
GREP. Whats Grep? Grep is a popular unix program that supports a special programming language for doing regular expressions The grammar in use for software.
Introduction to Database using Microsoft Access 2013 Part 6.1 November 18, 2014.
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 5 Regular Expressions.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
Regular expressions Day 11 LING Computational Linguistics Harry Howard Tulane University.
Regular Expressions In Javascript cosc What Do They Do? Does pattern matching on text We use the term “string” to indicate the text that the regular.
Regular Expressions.
Regular Expressions Upsorn Praphamontripong CS 1110
CS 330 Class 7 Comments on Exam Programming plan for today:
Perl Regular Expression in SAS
Strings and Serialization
Looking for Patterns - Finding them with Regular Expressions
Lecture 19 Strings and Regular Expressions
Advanced Regular Expressions
Regular Expressions (RegEx)
Perl-Compatible Regular Expressions Part 1
Corpus Linguistics I ENG 617
CSE 390a Lecture 7 Regular expressions, egrep, and sed
Topics in Linguistics ENG 331
Advanced Find and Replace with Regular Expressions
CSE 390a Lecture 7 Regular expressions, egrep, and sed
CS 1111 Introduction to Programming Fall 2018
Data Manipulation & Regex
Matcher functions boolean find() Attempts to find the next subsequence of the input sequence that matches the pattern. boolean lookingAt() Attempts to.
Regular expressions, egrep, and sed
Lecture 25: Regular Expressions
Regular expressions, egrep, and sed
Regular expressions, egrep, and sed
CSE 390a Lecture 7 Regular expressions, egrep, and sed
REGEX.
ADVANCE FIND & REPLACE WITH REGULAR EXPRESSIONS
Lecture 23: Regular Expressions
Presentation transcript:

Regular Expressions BKF03 Brian Ciccolo

Agenda Definition Uses – within Aspen and beyond Matching Replacing

Whats a Regular Expression? In computing, regular expressions, also referred to as regex or regexp, provide a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.

Why Use a Regex? Validate data entry Example: Verify the format of a date field is mm/dd/yyyy Find/replace on steroids Example: Reformat phone numbers to (###) ###-####

Regex Use in Aspen Data validation o Date, time field input o Validation rules (new in 3.0 – see session TEC07) Find/replace on steroids o System Log filter o Field formatting

RegEx Examples Using Notepad++ Select the proper Search Mode Select this option for our examples

Matching – The Basics Literals - plain old text Classes ExampleDefinition [abc]a, b, or c [a-z]Any lowercase letter [a-zA-Z]Any lowercase or uppercase letter [0-9]Any digit, 0 through 9 [^a-zA-Z]Not a letter (could be a digit or punctuation)

Matching – Predefined Classes Predefined Class Definition.Any character \dAny digit: [0-9] \DAny non-digit: [^0-9] \sA whitespace character (space, tab, newline) \SA non-whitespace character: [^\s] \wA word character: [a-zA-Z_0-9] \WA non-word character (i.e., punctuation): [^\w]

Matching – Quantifiers QuantifierDefinition ? Matches 0 or 1 time (Not supported by Notepad++) +Matches 1 or more times *Matches 0 or more times {n,m} Matches at least n times but no more than m times (Not supported by Notepad++)

Matching – Greedy vs. Lazy Quantifiers are greedy by default – they match as many characters as possible Sometimes you want to match the fewest characters possible – enter lazy quantifiers QuantifierLazy Equivalent* ??? ++? **? * Not supported by Notepad++

Replacing – Groups Groups in the regex can be used in the replacement value Delimited with parentheses in the regex Identified with \n where n is the n th group in the original expression \0 represents the entire match (not supported in Notepad++)

Reformatting Dates Change mm/dd/yyyy to yyyy-mm-dd Regex: (\d+)/(\d+)/(\d+) Replacement: \3-\1-\2 Step 2 – pad the single digits! Regex: -(\d)([-"]) Replacement: -0\1\2

Reformatting Phone Numbers (v1) Wrap the area code in parentheses Regex: "(\d\d\d)- Replacement: "(\1) Ends with a space!

Reformatting Phone Numbers (v2) Strip punctuation (numbers only) Regex: \((\d+)\) (\d+)-(\d+) Replacement: \1\2\3

Reformatting Social Security Numbers Format SSN as ###-##-#### Do it in Aspen! Define a record in the Regular Expression Library table Set the regex on the Person ID field in the Data Dictionary

Define a Regular Expression Regex and format properties

Update the Data Dictionary Link to the regex

Verify the Results

Extras Wikipedia Entry Regular Expressions Cheat Sheet (V2) Java regex support Notepad++ text editor and regex support

Thank you.