Вопрос

Assume that my string is "sample text – and so on.."

in perl we have use backslash while matching in some cases like : sample text \&\#x2013\; and so on..

I want to know is there any other way to match any string instead of using backslashes while matching?

Это было полезно?

Решение

Anytime you want to use a literal string for comparison inside a regular expression, just use quotemeta on it.

There are also some helpful escape codes to shortcut that process, \Q ... \E, which can be included inside a double quoted string or regex LHS to escape special characters.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top