Мастер-классы по Javascript Екатеринбург Ростов-на-Дону Москва Узнать больше...
Содержание (скрыть) Содержание (показать)

Difference "[^"]*" and ".*?"

Are "[^"]" and ".?" the same?

In other words, is it possible that they give different results? If yes, then provide the test string.

Решение
Решение

In general, yes, they are almost the same. Both match from one quote to the other.

But the gotcha is dot symbol '.'. Remember, dot '.' is any character excepts a newline.

And [^"] is any character except a quote '"'.

So, the first regexp "[^"]" will match quoted strings with newlines, but not the second regexp ".?" will not.

showMatch( ' "multiline \n string " ', /"[^"]*"/g )

showMatch( ' "multiline \n string " ', /".*?"/g )

#202
Наверх

Реклама

Нашли опечатку?

Нашли опечатку на сайте? Что-то кажется странным?
Выделите соответствующий текст и нажмите Ctrl+Enter!

Последние Комментарии

Помоги другим!

Помоги другим узнать о хорошей статье!