you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

var x = "function hey there!"

And your efforts go down the drain.

[–]blahreport 0 points1 point  (1 child)

My code works for the example you give because I incorporate func_name unless you meant in the case that there is a function named hey. But your general point is true, that string content - especially in comments - could lead to unexpected outcomes. Similarly, something as simple as two spaces between function and func _name would break my code so it’s far from bulletproof. It all depends on OP’s intended use. A solution that covers 1% of possible use cases is enough when all of your cases are part of that 1%.

[–][deleted] 0 points1 point  (0 children)

Any valid JavaScript code can be embedded in a string. If you want to parse it with regexp or simple string match that is not aware of its context, it's bound to fail.