write a regex that matches "s, n" in javascript

You can use the RegExp constructor with the pattern "s, n" to create a regular expression that matches the literal string "s, n". Here's an example:

index.tsx
const regex = new RegExp("s, n");
const myString = "This is a string that contains s, n in it.";
const match = myString.match(regex);
console.log(match); // ["s, n"]
166 chars
5 lines

In this example, we create a regular expression object regex that matches the string "s, n". We then create a sample string that includes this sequence of characters, and use the match method to find the match in the string. The match method returns an array containing the matched substring, which in this case is ["s, n"].

Alternatively, you can use the shorthand regex syntax /s, n/ to achieve the same result:

index.tsx
const regex = /s, n/;
const myString = "This is a string that contains s, n in it.";
const match = myString.match(regex);
console.log(match); // ["s, n"]
154 chars
5 lines

The result is the same as in the previous example.

gistlibby LogSnag