Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 5
    Just because you crammed 10 statements into one line, it's not a one-liner :) Commented Apr 30, 2021 at 8:48
  • 2
    10 statements? It's just a ternary expression, and if it's one line, it's a one liner ;) And if you say it's 3 line because of the function that's just for readability otherwise you can do const stringToRegex = (s, m) => (m = s.match(/^([\/~@;%#'])(.*?)\1([gimsuy]*)$/)) ? new RegExp(m[2], m[3].split('').filter((i, p, s) => s.indexOf(i) === p).join('')) : new RegExp(s); Commented Apr 30, 2021 at 14:29
  • Readable and RegExp? LOL Commented Aug 13, 2022 at 6:08
  • Nice. this seems to be the only useful answer to the question. Commented Mar 2, 2023 at 19:03