Regex Challenge

What does ?= do at the beginning ? since it checks if a pattern or character is followed by something like x(?=y) Why do we need it at the beginning?

FCC Solution


The lookahead starts at the current position. This link seems to provide a good explanation - Lookahead and Lookbehind Tutorial—Tips &Tricks

For the x(?=y) example, the current position is after the x and the lookahead checks for a y at that position.

For your (?=\w{6})(?=\w*\d{2}) example, you want it to look through the whole value, starting at the beginning.

Here’s a regex explainer/tester that shows both a flow-chart of what the regex does and lets you test values to see if they match - Online Regex tester and visualizer - Python, PHP, Ruby, JavaScript, Java

1 Like

The link you have attached provides a great explanation and it has a an advanced example of password validation. Thank you! not finding solution checkbox here

From what I understand now using the lookaheads at every group of the expression will not return a matched pattern but it only tests if true or false

Seems to have been removed.

Edit: It apparently only exists in some of the forum sections.

Indeed I have only seen it in the beginners -PHP category

Sponsor our Newsletter | Privacy Policy | Terms of Service