Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Support of \K in regex

Tags:

regex

The \K escape sequence resets the beginning of the match to the current position in the token list (this only affects what is reported as the full match).

What environments/languages/versions support \K (keep) in its regular expression engines and what libraries are needed (if any) to use this feature within patterns?

like image 993
Ωmega Avatar asked Nov 24 '12 16:11

Ωmega


People also ask

What does regex 0 * 1 * 0 * 1 * Mean?

Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.

What does '$' mean in regex?

Literal Characters and Sequences For instance, you might need to search for a dollar sign ("$") as part of a price list, or in a computer program as part of a variable name. Since the dollar sign is a metacharacter which means "end of line" in regex, you must escape it with a backslash to use it literally.

How does regex handle special characters?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).

What languages support regex?

Regex support is part of the standard library of many programming languages, including Java and Python, and is built into the syntax of others, including Perl and ECMAScript. Implementations of regex functionality is often called a regex engine, and a number of libraries are available for reuse.


1 Answers

The \K escape sequence is supported by several engines, languages or tools, such as:

  • boost (since ???)
  • grep -P                                                     ← uses PCRE
  • Oniguruma (since 5.13.3)
  • PCRE (since 7.2)
  • Perl (since 5.10.0)
  • PHP (since 5.2.4)
  • Ruby (since 2.0.0)
  • Notepad++ (since 6.0)

...and (so far) not supported by:

  • .NET
  • awk
  • bash
  • ICU
  • Java
  • Javascript
  • Objective-C
  • POSIX
  • Python
  • Qt/QRegExp
  • sed
  • Tcl
  • vim        ← it doesn't have \K, but its \zs is equivalent
  • XML
  • XPath
like image 143
38 revs, 9 users 47% Avatar answered Sep 23 '22 04:09

38 revs, 9 users 47%