# Confusion with regex lookaheads

**URL:** <https://forum.freecodecamp.org/t/confusion-with-regex-lookaheads/269708>\
**Category:** General\
**Created:** [April 7, 2019, 12:09am UTC](https://forum.freecodecamp.org/t/confusion-with-regex-lookaheads/269708 "2019-04-07T00:09:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KnackwurstBagel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/knackwurstbagel/32/113505_2.png) [@KnackwurstBagel](https://forum.freecodecamp.org/u/KnackwurstBagel)\
**Post date:** [April 7, 2019, 12:09am UTC](https://forum.freecodecamp.org/t/confusion-with-regex-lookaheads/269708/1 "2019-04-07T00:09:50Z")

</div>

I am doing the Regex part of the “Javascript Algorithms and Data Structures Certification” and am stuck on lookahead’s

Does a lookahead not count toward the number of characters matched? When I use the following regex  
[Regex with lookahead](https://regex101.com/r/Hk4CJb/2)

it matches with 1234 where I would expect it to fail, my logic is that [at least 4 word characters] followed by [2 digits] should mean the string would need to be 6 characters long. It almost feels like the lookaheads are ignoring each other and I do not understand why.

Can someone explain why a 4 digit number is matching?

---

<div class="post-metadata">

**Author:** ![kravmaguy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kravmaguy/32/179611_2.png) [@kravmaguy](https://forum.freecodecamp.org/u/kravmaguy)\
**Post date:** [April 7, 2019, 1:55am UTC](https://forum.freecodecamp.org/t/confusion-with-regex-lookaheads/269708/2 "2019-04-07T01:55:14Z")

</div>

Which challenge are you specifically trying to pass that is not working?  
Make a new post, Share the challenge your trying to pass here it should automatically include the work you did on it so we can better answer your question.

Regarding look aheads there are positive and negative look aheads,  
x(?=y) positive lookahead (matches ‘x’ when it’s followed by ‘y’)  
x(?!y) negative lookahead (matches ‘x’ when it’s not followed by ‘y’)

there are also look behinds…

---

<div class="post-metadata">

**Author:** ![KnackwurstBagel](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/knackwurstbagel/32/113505_2.png) [@KnackwurstBagel](https://forum.freecodecamp.org/u/KnackwurstBagel)\
**Post date:** [April 7, 2019, 2:05am UTC](https://forum.freecodecamp.org/t/confusion-with-regex-lookaheads/269708/3 "2019-04-07T02:05:40Z")

</div>

Thank you kravmaguy, the particular challenge is [Positive and Negative Lookahead](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead) however Im stuck on understanding how the lookaheads work rather than not being able to pass the challenge. As I have completed it and moved on, I do not understand why my answer worked.

Does two consecutive lookaheads not work together to make the match? I expected the first part to add with the second part.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:03pm UTC](https://forum.freecodecamp.org/t/confusion-with-regex-lookaheads/269708/5 "2021-01-17T20:03:23Z")

</div>


