Skip to content

Instantly share code, notes, and snippets.

@bsodmike
Last active June 3, 2022 08:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsodmike/5784361 to your computer and use it in GitHub Desktop.
Save bsodmike/5784361 to your computer and use it in GitHub Desktop.
Solutions to Lessons @ RegexOne.com

Objective:

match   can
match   man
match   fan
skip    dan
skip    ran
skip    pan

Solutions:

([cmf]+[an]+)[^d]
([cmf]+[an]{2})[^d]

Objective:

match   hog
match   dog
skip    bog

Solutions:

([d-o]+)[^bg]

Objective:

match Ana
match Bob
match CpC
skip  aax
skip  bby
skip  ccz

Solutions:

([A-Ca-p]+)[^a-cx-z]

Objective:

match   wazzzzup
match   wazzzup
skip    wazup

Solutions:

([wa]+[z]{3,4}[up]+)

Objective:

match   aaaabcc
match   aabbbbc
match   aacc

Solutions:

(a+b*c+)

Objective:

match   1 file found?
match   2 files found?
match   x files found?

Solutions:

([\d\w+]\s[file?s]+\sfound\?)

Objective:

match   1.   abc
match   2.    abc
match   3.                   abc
skip    4.abc

Solutions:

([\d\.]+\s+[a-c]+)          # matches any whitespace
([\d\.]+[" "|\t]+[a-c]+)    # specifically matches spaces and tab-based whitespace

Objective:

match   Mission: successful
skip    Last Mission: unsuccessful
skip    Next Mission: successful upon capture of target

Solutions:

^([a-zA-z]+\:\s?successful)$

Objective:

match   file_a_record_file.pdf
match   file_yesterday.pdf
skip    testfile_fake.pdf.tmp    

Solutions:

([a-z+\_?]+)\.pdf$
([a-z+\_?]+)(?=\.pdf$)      # using positive lookahead

Objective:

match   Jan 1987    capture     Jan 1987, 1987
match   May 1969    capture     May 1969, 1969
match   Aug 2011    capture     Aug 2011, 2011

Solutions:

^([a-zA-z]+\s+([\d]+))$
@arifams
Copy link

arifams commented Mar 25, 2016

Thanks man. I was stuck and luckily found this gem, cool :)
Lesson 12 i tried with ^(.*([0-9]{4}))$ and it works somehow (well I was quite surprised)

@lifesucx
Copy link

lifesucx commented Apr 9, 2019

For lesson 11 the bottom solution works, but instead of an underscore it should be 0-9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment