DVGY
January 8, 2020, 10:54am
1
Tell us what’s happening:
How the below expression matches this string thisIsSpinalTap
. Since here I does not have a space or _ before so how does it match ?
Your code so far
return str.split(/\s|_|(?=[A-Z])/)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
.
Challenge: Spinal Tap Case
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case
ilenia
January 8, 2020, 11:47am
2
DVGY:
(?=[A-Z])
this part here match before a capital letter
see the purple line (it is where it matches):
ilenia
January 8, 2020, 11:48am
3
please stop putting solutions without spoiler tags - it is the second one today
DVGY
January 8, 2020, 11:52am
4
I am so sorry. I thought i can put a single line of code without that tag
DVGY
January 8, 2020, 11:55am
5
x(?=y) – positive lookahead (matches 'x' when it's followed by 'y')
Since x is not present how it is valid ?
ilenia
January 8, 2020, 11:59am
6
x(?=y)
matches the x
if it is followed by y
(?=y)
matches the point before the y
you can play with an online tester if it can help clear your ideas in how things work: https://regex101.com/
DVGY
January 8, 2020, 12:03pm
7
const consonantCluster = str.match(/^[^aeiou]+/)[0]
What is this weird syntax at the end you can see [0], when i remove zero output remains the same
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin
DVGY
January 8, 2020, 12:06pm
8
(?=y) matches the point before the y
I tried to find it on MDN but this reference was not available. Where did u get it from ?
ilenia
January 8, 2020, 12:42pm
9
it is what happens, try on the regex tester online, try to do "xyxxyyyxux".split(/(?=y)/)
, it will split before the y
Matches at a position where the pattern inside the lookahead can be matched. Matches only the position. It does not consume any characters or expand the match. In a pattern like one(?=two)three, both two and three have to match at the position where the match of one ends.
source: https://regular-expressions.mobi/refadv.html?wlr=1
match
returns an array, with the [0]
it is selecting the first element in the array from match
1 Like