Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/leta91/winter-is-coming-house-of-the-dragon

How to find characters with lazy matching
https://github.com/leta91/winter-is-coming-house-of-the-dragon

beginner-friendly fcc freecodecamp freecodecamp-challenge game-of-thrones gameofthrones got house-of-the-dragon houseofthedragon javascript js regular-expression regular-expressions winteriscoming

Last synced: 6 days ago
JSON representation

How to find characters with lazy matching

Awesome Lists containing this project

README

        

# Find Characters with Lazy Matching (freeCodeCamp Challenge)
Inspired by Game of Thrones, House of The Dragon sequel ❄️🔥

## "Regular Expressions" ➡️ Chapter 3
## Part of the JavaScript Certification ➡️ Lesson 14

### In regular expressions there are 2 types of matches:
1. greedy match (by default) = it finds the *longest possible* part of a string that matches the regex pattern
2. lazy match = it finds the *shortest possible* part

#### Complete the Challenge:
Fix the regex `/<.*>/` to return the HTML tag `

` and not the text `"

Winter is coming

"`

Initially we have `let myRegex = /<.*>/;` that we have to change

let's analyze the solution `/.h[0-9]*?>/`
- wildcard `.` corresponds to any character
- [0-9] any number between 0 and 9 to follow the letter `h`
- `?` corresponds to lazy matching that ends with this character `>`