문제

I'm trying to write a regex that would detect regex in a javascript file. I've spent some time and this is what I've come up with:

\/.*?\/[a-zA-Z]?

This works fine:

/^[^0-9][2,3]$/
/^[a-z]+( +[a-z]+){2,}$/g

However it fails for something like this:

/\/.*?\/[a-zA-Z]?/g

Just to clarify my goal, I'm going to be using this regex to detect regexes in JavaScript code and color code them.

도움이 되었습니까?

해결책

You should also check whether the / is preceeded by a \ or not to make sure it is not being escaped:

(?<!\\)\/.*?(?<!\\)\/[a-zA-Z]?

DEMO

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top