Maverick Maverick - 6 months ago 12
Javascript Question

Select everything between not starting with but ending with

So I am trying to select some names with JS but I can figure out how. I found 3 solution here but still could not get it to work:

I would like to select word that DOESN'T start with

.
and HAS to end with
{


Here is what I have:
\b(?!\.)[\w\-]+(?=\s*{)\b


Also tried:
^(?!\.)[\w\-]+(?=\s*:)


Example:



.test { }

test { } <--- Select this test

Answer

([^\S\.]|^)([^\s\.]+(?=\{))

See https://regex101.com/r/bT8sE5/1 for a live demo with further explanation.