Skip to content

Instantly share code, notes, and snippets.

View GarrettAnderson's full-sized avatar

Garrett Lee Graham Anderson GarrettAnderson

  • Longwood, FL
View GitHub Profile

Explaining a Regular Expression

A regex, which is short for regular expression, is a sequence of characters that defines a specific search pattern. When included in code or search algorithms, regular expressions can be used to find certain patterns of characters within a string, or to find and replace a character or sequence of characters within a string.

Summary

Below we will discuss how to implement a regular expression to find an email matching the search criteria. Using the following, /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/, I will detail the various components of the regex and explain what is occuring. Regular expressions begin and end with forward slashes, /, in order to indicate the search parameters and define itself as a regex.

Table of Contents

min = 1
max = 100
guess = 0
tries = 0
puts "Please, choose a number between #{min} and #{max}"
# puts "What is your answer"
# answer = gets.chomp
# puts answer
+----------------+----------+-----------------------------+-------------------+-------------+-----------------------+-----------------+
| full_name | salary | position | phone_extension | part_time | parking_spot_number | department_id |
|----------------+----------+-----------------------------+-------------------+-------------+-----------------------+-----------------|
| Dedicated Doug | 450 | software developer | 323 | False | <null> | 4 |
| Crazy Carry | 500 | cook | 312 | False | <null> | 5 |
| Bashful Berry | 500 | janitor | 553 | False | <null> | 3 |
| Gracious Gary | 500 | instructor | 22 | False | <null> | 6 |
| Rigid Roger | 650 | manager | 10
select * from employees;
+----------------+----------+------------------+-------------------+------------
| full_name | salary | position | phone_extension | part_time
|----------------+----------+------------------+-------------------+------------
| Lazy Lynn | 450 | accountant | 403 | False
| Crazy Carry | 500 | human resources | 312 | True
| Rigid Roger | 650 | management | 10 | False
| Gracious Gary | 500 | dev ops | 22 | True
| Terrible Terry | 320 | internal affairs | 212 | False
+----------------+----------+------------------+-------------------+------------
FILTER OUT THE GEESE
function gooseFilter (birds) {
var geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"];
// return an array containing all of the strings in the input array except those that match strings in geese
var filterOutGeese = birds.filter(function(birds) {
return geese.indexOf(birds) < 0;
})
return filterOutGeese;
}
@GarrettAnderson
GarrettAnderson / gist:a17d708361109680d057abff6ca05b2a
Created February 13, 2019 15:24
Feb_13_Code Kata - Tip Calculator
function calculateTip(amount, rating) {
var rating2 = rating.toLowerCase()
if (rating2 === 'terrible' || rating2 === 'Terrible') {
var tipPercent = 0.00;
var totalTip = Math.ceil(amount * tipPercent);
return totalTip;
} else if (rating2 === 'poor' || rating2 === 'Poor') {
var tipPercent = 0.05;
var totalTip = Math.ceil(amount * tipPercent);
return totalTip;
const volumeOfCube = (height, volume, width) => {
let volume = height * volume * width
return volume
}