std::regex, to match begin/end of string

前端 未结 4 1361
误落风尘
误落风尘 2020-12-31 05:46

In JS regular expressions symbols ^ and $ designate start and end of the string. And only with /m modifier (multiline

4条回答
  •  梦毁少年i
    2020-12-31 06:23

    You can emulate Perl/Python/PCRE \A, which matches at beginning of string but not after a newline, with the Javascript regex ^(?, which translates to English as "match the beginning of a line which has no preceding character".

    You can emulate Perl/Python/PCRE \z, which matches only at end-of-string, using (?!(.|\n))$. To get the effect of \Z, which matches only at end-of-string but allows a single newline just before that end-of-string, just add an optional newline: \n?(?!(.|\n))$.

提交回复
热议问题