Get an example matched text from a regex pattern

Viewed 56

Is there any way I can extract one example text that matches in a regex pattern?

For example: Suppose that we have this regular expression pattern in JavaScript /^No I do(n't| not)\.?$/

There are multiple sentences which are valid in that: "No I don't", "No I do not", "No I don't.", "No I do not."

Is there a code or method or function that suggests at least one of these? (Driven just from the regex pattern)

/^No I do(n't| not)\.?$/ = = = > ["No I don't", "No I do not", "No I don't.", "No I do not."] or just "No I don't"

0 Answers
Related