Regex — 60 questions
Play ▸- #1 · What does this expression return? /cat/.test('concatenate')
- #2 · Which input does this pattern NOT match? /^a.c$/ // tested against each input
- #3 · What does this expression return? 'banana'.search(/an/)
- #4 · What does this expression return? ['catfish', 'hotdog'].map(s => /^cat|dog$/.test(s)
- #5 · What does this expression return when nothing matches? 'hello'.match(/xyz/)
- #6 · What does this expression return? 'a1b2c3'.replace(/\d/, '')
- #7 · Which input does this pattern match? /^colou?r$/
- #8 · What does this expression return? 'a1b22c333'.match(/\d+/g)
- #9 · Which input does this pattern match? /^\d{2,4}$/
- #10 · What does this expression return? 'aaa'.match(/a*/g)
- #11 · Which input does this pattern NOT match? /^ab*c$/
- #12 · In JavaScript (without the
u/v flags), which class is equivalent to \w?
- #13 · What does this expression return? 'regex'.replace(/[aeiou]/g, '')
- #14 · What does this expression return? '2024-01-15'.match(/[^-]+/g)
- #15 · What does this expression return? /[\b]/.test('a b')
- #16 · What does this expression return? /^[A-z]$/.test('_')
- #17 · In POSIX ERE (
grep -E), which bracket expression matches a single digit? echo "a1 b22" | grep -oE '<class>+'
- #18 · What does this expression return? /^hi/.test('oh hi')
- #19 · Which pattern matches file names that end in
.js?
- #20 · What does this expression return? 'cat concat cats'.match(/\bcat\b/g)
- #21 · In Python
re, what does this tuple evaluate to? import re (bool(re.search(r'^abc$', 'abc\n')), boo
- #22 · What does this expression return? 'cat concat'.replace(/\Bcat/g, 'X')
- #23 · What does this expression return? '2024-06-15'.match(/(\d+)-(\d+)/)[2]
- #24 · What does this expression return? 'John Smith'.replace(/(\w+) (\w+)/, '$2, $1')
- #25 · What does this expression return? '06/2024'.replace(/(?<m>\d+)\/(?<y>\d+)/, '$<y>-$<
- #26 · What does this expression return? 'bookkeeper'.match(/(\w)\1/g)
- #27 · What does this expression return? 'abc'.match(/(\w)+/)[1]
- #28 · What does this expression return? 'a1b2c'.split(/(\d)/)
- #29 · What does this expression return? '100USD 200EUR'.match(/\d+(?=EUR)/)[0]
- #30 · Which input does this pattern match? /^(?!test)\w+$/
- #31 · What does this expression return? '$5, $10, €7'.match(/(?<=\$)\d+/g)
- #32 · Which password does this pattern accept? /^(?=.*\d)(?=.*[A-Z]).{8,}$/
- #33 · What does this expression return? 'abc'.replace(/(?=b)/, '-')
- #34 · What does this expression return? 'x1 y2 x3'.match(/(?<!x)\d/g)
- #35 · What does the
i flag do? /hello/i
- #36 · What happens when this runs? 'aaa'.replaceAll(/a/, 'b')
- #37 · What does this expression return? [/a.b/.test('a\nb'), /a.b/s.test('a\nb')]
- #38 · What does the final expression return? const re = /\d/y; re.lastIndex = 0; [re.test('a1')
- #39 · What does this expression return? ['😀'.match(/./g).length, '😀'.match(/./gu).length
- #40 · What does this expression return? 'a1\nb2'.match(/^\w/gm)
- #41 · What does this expression return? '"a" and "b"'.match(/".*"/)[0]
- #42 · What does this expression return? '<b>x</b>'.match(/<.+?>/)[0]
- #43 · What does this expression return? 'aaa'.match(/^a+?$/)[0]
- #44 · What does this expression return? 'xaaay'.match(/a*?/)[0]
- #45 · Which PATTERN captures only the first bracketed value? '[a][b]'.match(PATTERN)[1] === 'a'
- #46 · In PCRE, does this pattern match "aaa"? /^a++a$/ // input: "aaa"
- #47 · Which pattern matches exactly the text
1+1?
- #48 · What does this expression return? '1.5'.replace(/./g, '#')
- #49 · What does this expression return? new RegExp('\d+').test('42')
- #50 · What does this expression return? 'a.b*c'.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
- #51 · What does this expression return? 'cost'.replace(/cost/, '$$5')
- #52 · With plain
grep (POSIX BRE), which lines does this print? printf 'a+\naaa\n' | grep 'a+'
- #53 · Which pattern matches a US ZIP code like
12345 or 12345-6789?
- #54 · Which input does this color pattern match? /^#([0-9a-f]{3}){1,2}$/i
- #55 · What does this expression return? ' hi '.replace(/^\s+|\s+$/g, '')
- #56 · What does this expression return? 'a b c'.replace(/\s+/g, ' ')
- #57 · What does this expression return? '1234567'.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
- #58 · Which IPv4 octet does this pattern accept? /^(25[0-5]|2[0-4]\d|1?\d?\d)$/
- #59 · What does this expression return? [...'k1=v1;k2=v2'.matchAll(/(\w+)=(\w+)/g)].map(m
- #60 · What does this expression return? '2024-06-15'.match(/^(\d{4})-(\d{2})-(\d{2})$/).sl