I am building myself a syntax highlighter for React tutorials. Currently I am trying to capture the variable assignment and de-structured properties when importing.
I am able to capture a single variable assignment like so...
code: import React from 'react';
regex: /(?<=\b(import|export|default)\s)(\w+)/gm
captures: React
However, when trying to capture that inline with de-structured properties it fails and I am running into unforseen issues.
Example
code: import React, { useState, useEffect } from 'react';
captures: React
I Need to capture React
, useState
, and useEffect
but not ,
, {
, or }
.
Regex is not my forte and I am unsure how to ask this question to get a proper answer. Any help would be appreciated.