Learning Ruby - 6 Regular Expressions. Ruby's Regex Technology Specifying what you are after using a terse, compact syntax Very useful when working with.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

John Pinney Ruby in 20 minutes John Pinney
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Learning Ruby Regular Expressions Get at practice page by logging on to csilm.usu.edu and selecting PROGRAMMING LANGUAGES|Regular Expressions.
Tutorial 6 Creating a Web Form
And other languages….  Selection Statements  Iterative Statements  Unconditional Branching  Not covered Guarded Commands.
REGULAR EXPRESSIONS FRIEND OR FOE?. INTRODUCTION TO REGULAR EXPRESSIONS.
ISBN Chapter 6 Data Types Character Strings Pattern Matching.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
The Ruby Programming Language
Prof. Alfred J Bird, Ph.D., NBCT Office – Wheatly 2nd floor Office Hours – MW 3:00PM.
Pattern matching with regular expressions A common file processing requirement is to match strings within the file to a standard form, e.g. address.
AND OTHER LANGUAGES… Ruby Regular Expressions. Why Learn Regular Expressions? RegEx are part of many programmer’s tools  vi, grep, PHP, Perl They provide.
CIT 383: Administrative Scripting
Regular Expressions – Friend or Foe? Primož Gabrijelčič.
Programming History. Who was the first programmer?
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Writing Methods.
Using CookCC.  Use *.l and *.y files.  Proprietary file format  Poor IDE support  Do not work well for some languages.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
New Perspectives on XML, 2nd Edition
Trends in Scripting Languages History For me the purpose of life is partly to have joy. Programmers often feel joy when they can concentrate on the creative.
CIS Intro to JAVA Lecture Notes Set 7 7-June-05.
Intro to Python Adriane Huber Debbie Bartlett Python Lab #1Python Lab #1 1.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
PEGs, Treetop, and Converting Regular Expressions to NFAs Jason Dew and Gary Fredericks.
+ Ruby and other programming Languages Ronald L. Ramos.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
RUBY by Ryan Chase.
LING 408/508: Programming for Linguists Lecture 14 October 19 th.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
Source Page US:official&tbm=isch&tbnid=Mli6kxZ3HfiCRM:&imgrefurl=
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
Tutorial 6 Creating a Web Form
Путешествуй со мной и узнаешь, где я сегодня побывал.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Math Expression Evaluation With RegEx and Finite State Machines.
Presented By P.SRIVIDYA 085D1A0552 Programming Language.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
Regular Expressions.
CSE 374 Programming Concepts & Tools
REGULAR EXPRESSION Java provides the java.util.regex package for pattern matching with regular expressions. Java regular expressions are very similar.
CSE 105 theory of computation
Looking for Patterns - Finding them with Regular Expressions
CSC 458– Predictive Analytics I, Fall 2017, Intro. To Python
Programming Language Design Concepts
CIT 383: Administrative Scripting
CompSci 230 Software Construction
Agile Web Development with Ruby and Rails
Page 1. Page 2 Page 3 Page 4 Page 5 Page 6 Page 7.
1 Python Lab #1 Intro to Python Adriane Huber Debbie Bartlett.
CIT 383: Administrative Scripting
What to do today: Brief history of Ruby General qualities/info
Развој софтвера 2.
Introduction to Python
CIT 383: Administrative Scripting
CSC 458– Predictive Analytics I, Fall 2018, Intro. To Python
Regular Expressions
i206: Lecture 19: Regular Expressions, cont.
Regular Expressions
Control Structures Part 3
Matcher functions boolean find() Attempts to find the next subsequence of the input sequence that matches the pattern. boolean lookingAt() Attempts to.
Understand the interaction between computer hardware and software
More Variables and Data Types: references/matricies
CIT 383: Administrative Scripting
Gavin Restifo March 1, 2019 Today: Repetition Part 2 - For Loops
CISC101 Reminders Assignment 3 due today.
Similarities Differences
Keyword Arguments aka Named Parameters in Ruby (and Python)
Computer Programming Tutorial
Presentation transcript:

Learning Ruby - 6 Regular Expressions

Ruby's Regex Technology Specifying what you are after using a terse, compact syntax Very useful when working with textual data Similar technology available in Perl, C#, Python and Java (to name a few) Think of regex's as a programming technology within a programming technology Refer to the handout "Paul's Ruby Regex Primer"

#! /usr/bin/ruby -w def show_regexp( target, regex ) # Based on the code from page 69, Programming Ruby, # 2nd Edition by Dave Thomas. if target =~ regex "#{$`}>>#{$&}<<#{$'}" else "no match found" end # of if. end # of show_regexp. target, regex = ARGV.collect { |arg| arg } regex = Regexp.new( regex ) puts show_regexp( target, regex ) A Useful Ruby Regex Processor

More... Ruby So Far Take the time to learn Ruby's regular expression syntax