#include <regex>
import re
import java.util.regex.Pattern;
foreach my $n (@names) {
print $n if $n =~ /REGEX_HERE/;
}
or
while (<>) {
print if /REGEX_HERE/;
}
# This is necessary to print every statement on a new line
# It is activating a feature that will be standard in Perl 6
use feature qw(say);
my @songs = ("God\'s Plan by Drake","Perfect by Ed Sheeran","Havana by Camila Cabello Featuring Young Thug","Rockstar by Post Malone Featuring 21 Savage","Finesse by Bruno Mars & Cardi B","Bad At Love by Halsey","Diplomatic Immunity by Drake","New Rules by Dua Lipa","Thunder by Imagine Dragons","No Limit by G-Eazy Featuring A$AP Rocky & Cardi B","MotorSport by Migos, Nicki Minaj & Cardi B","Meant To Be by Bebe Rexha & Florida Georgia Line","Too Good At Goodbyes by Sam Smith","Let You Down by NF","Love. by Kendrick Lamar Featuring Zacari","Him & I by G-Eazy & Halsey","Gucci Gang by Lil Pump","Gummo by 6ix9ine","I Fall Apart by Post Malone","Bartier Cardi by Cardi B Featuring 21 Savage","How Long by Charlie Puth","Shape Of You by Ed Sheeran","Bodak Yellow (Money Moves) by Cardi B","I Get The Bag by Gucci Mane Featuring Migos","Feel It Still by Portugal. The Man","Wolves by Selena Gomez X Marshmello","Plain Jane by A$AP Ferg","Believer by Imagine Dragons","Sky Walker by Miguel Featuring Travis Scott","End Game by Taylor Swift Featuring Ed Sheeran & Future","Roll In Peace by Kodak Black Featuring XXXTENTACION","Sorry Not Sorry by Demi Lovato","Filthy by Justin Timberlake","River by Eminem Featuring Ed Sheeran","Young Dumb & Broke by Khalid","Marry Me by Thomas Rhett","Never Be The Same by Camila Cabello","Lights Down Low by MAX Featuring gnash","Ric Flair Drip by Offset & Metro Boomin","Lemon by N*E*R*D & Rihanna","What Lovers Do by Maroon 5 Featuring SZA","The Way Life Goes by Lil Uzi Vert Featuring Nicki Minaj","Keke by 6ix9ine, Fetty Wap & A Boogie Wit da Hoodie","Mi Gente by J Balvin & Willy William Featuring Beyonce","Let Me Go by Hailee Steinfeld & Alesso Featuring Florida Georgia Line & Watt","1-800-273-8255 by Logic Featuring Alessia Cara & Khalid","Bank Account by 21 Savage","Attention by Charlie Puth","Yours by Russell Dickerson","Unforgettable by French Montana Featuring Swae Lee","Outside Today by YoungBoy Never Broke Again","Stir Fry by Migos","Pills And Automobiles by Chris Brown Featuring Yo Gotti, A Boogie Wit da Hoodie & Kodak Black","All The Stars by Kendrick Lamar & SZA","Good Old Days by Macklemore Featuring Kesha","Mine by Bazzi","Nowadays by Lil Skies Featuring Landon Cube","Pick It Up by Famous Dex Featuring A$AP Rocky","Greatest Love Story by LANCO","Written In The Sand by Old Dominion","No Smoke by YoungBoy Never Broke Again","Losing Sleep by Chris Young","Like I Loved You by Brett Young","Five More Minutes by Scotty McCreery","Sick Boy by The Chainsmokers","This Is Me by Keala Settle & The Greatest Showman Ensemble","Heaven by Kane Brown","Echame La Culpa by Luis Fonsi & Demi Lovato","Rubbin Off The Paint by YBN Nahmir","You Broke Up With Me by Walker Hayes","Supplies by Justin Timberlake","Codeine Dreaming by Kodak Black Featuring Lil Wayne","Betrayed by Lil Xan","Red Roses by Lil Skies Featuring Landon Cube","One Foot by WALK THE MOON","La Modelo by Ozuna x Cardi B","Rewrite The Stars by Zac Efron & Zendaya","Candy Paint by Post Malone","Tell Me You Love Me by Demi Lovato","Round Here Buzz by Eric Church","All On Me by Devin Dawson","No Name by NF","King\'s Dead by Jay Rock, Kendrick Lamar, Future & James Blake","MIC Drop by BTS Featuring Desiigner","Broken Halos by Chris Stapleton","Kooda by 6ix9ine","Legends by Kelsea Ballerini","Wait by Maroon 5","Best Friend by Sofi Tukker Featuring NERVO, The Knocks & Alisa Ueno","Ice Tray by Quavo & Lil Yachty","Beautiful Trauma by P!nk","IDGAF by Dua Lipa","Corazon by Maluma X Nego do Borel","Mayores by Becky G Featuring Bad Bunny","The Greatest Show by Hugh Jackman, Keala Settle, Zac Efron, Zendaya & The Greatest Showman Ensemble","Never Enough by Loren Allred","My Dawg by Lil Baby","I\'ll Name The Dogs by Blake Shelton","Rock by Plies","Female by Keith Urban")
say join "\n", @songs[0..5];
foreach my $s (@songs) {
say $s if $s =~ /Love/;
}
foreach my $s (@songs) {
say $s if $s =~ /M.n/;
}
foreach my $s (@songs) {
say $s if $s =~ /W[oa]l/;
}
foreach my $s (@songs) {
say $s if $s =~ /[,']/;
}
foreach my $s (@songs) {
say $s if $s =~ /[1-9]/;
}
foreach my $s (@songs) {
say $s if $s =~ /Lov[^e]/;
}
foreach my $s (@songs) {
say $s if $s =~ /\d\d/;
}
foreach my $s (@songs) {
say $s if $s =~ /by\s\d\d/;
}
# Write a regular expression that finds all songs/artists in the top 100 with
# two capital letters right next to each other
foreach my $s (@songs) {
say $s if $s =~ /[A-Z][A-Z]/;
}
# Write a regular expression that finds all songs/artists in the top 100 with
# a 'word' made up of only non-alphanumeric characters
foreach my $s (@songs) {
say $s if $s =~ /\s\W\s/;
}
foreach my $s (@songs) {
say $s if $s =~ /\sYou\s|\sMe\s/;
}
foreach my $s (@songs) {
say $s if $s =~ /\s(You|Me)\s/;
}
foreach my $s (@songs) {
say $s if $s =~ /Not?\s/;
}
foreach my $s (@songs) {
say $s if $s =~ /Lov.*You/;
}
foreach my $s (@songs) {
say $s if $s =~ /St\w+\s/;
}
foreach my $s (@songs) {
say $s if $s =~ /You\w+.*\sby\s/;
}
foreach my $s (@songs) {
say $s if $s =~ /D\w{1,4}g/;
}
foreach my $s (@songs) {
say $s if $s =~ /\s(\w\w\w\w)+\s/;
}
foreach my $s (@songs) {
say $s if $s =~ /(\d\w\w){2,}/;
}
# Write a regular expression that finds all songs in
# the top 100 with more than two artist on
# them (don' worry about "featuring" at first
# , but feel free to add it as a challenge)
foreach my $s (@songs) {
say $s if $s =~ /by\s([\s\w]+[,&]){2,}/;
}
# Write a regular expression that finds all songs in the top 100 with
# that have both the words "You" and "Me" in the title
foreach my $s (@songs) {
say $s if $s =~ /(You[\s\w]*Me|Me\s.*You)\s.*by/;
}
foreach my $s (@songs) {
if ($s =~ /St.+l/){
# $& is the part of the string that matched our pattern
say $s . " : " . $&
}
}
foreach my $s (@songs) {
if ($s =~ /St.+?l/){
say $s . " : " . $&
}
}
foreach my $s (@songs) {
say $s if $s =~ /^St\w+/;
}
foreach my $s (@songs) {
say $s if $s =~ /^You.*/;
}
foreach my $s (@songs) {
say $s if $s =~ /[A-Z]$/;
}
foreach my $s (@songs) {
say $s if $s =~ /s$/;
}
# Write a regular expression that finds all songs in the top 100
# that start with the word 'The'
foreach my $s (@songs) {
say $s if $s =~ /^The/;
}
# Write a regular expression that finds all songs in the top 100
# only have two words in the title
foreach my $s (@songs) {
say $s if $s =~ /^\S+\s\S+\sby/;
}
foreach my $s (@songs) {
say $s if $s =~ /by\bCardi B/;
}
foreach my $s (@songs) {
say $s if $s =~ /by\sCardi B/;
}
foreach my $s (@songs) {
say $s if $s =~ /\./;
}
foreach my $s (@songs) {
say $s if $s =~ /\bof\b/i;
}
# Write a regular expression that finds all songs in the top 100
# a character besides a alphanumeric or a space in the title
foreach my $s (@songs) {
say $s if $s =~ /.*[^\s\w].*by/;
}