To find strings between quotes in a TypeScript string using regex, you need to create a regular expression that uses capturing groups to extract the desired text.
Here's an example:
index.ts276 chars15 lines
In this example, we first create a TypeScript string with some text that contains words in quotes. Then, we create a regular expression that matches any text between two double quotes, using a capturing group that matches any character that is not a double quote (([^"]*)
).
After that, we create an empty array to store our matches, and then use a while
loop to execute the regular expression on the text and push each captured group to our matches array.
Finally, we log the array to the console to see the resulting matches.
Note that we use the g
flag on the regular expression to indicate that we want to search for multiple matches, not just the first one.
gistlibby LogSnag