Skip to content
Myr

Fix regular expression section on PCRE (fix #2439), also improve example format (#2613)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by itchyny · committed by GitHub · parent 433b79d · Browse files · 3 files+46 added−44 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+46 added−44 removed

  • other:+46 added−44 removed

3 files+46 added−44 removed

modified:docs/content/manual/v1.5/manual.yml+16 added-15 removed
1952 unmodified lines
1953 input: '[{}, true, {"a":1}]'1954 output: ['[null, 1]']195519561957 - title: Regular expressions (PCRE)1957 - title: Regular expressions1958 body: |19591960 jq uses the Oniguruma regular expression library, as do php,1961 ruby, TextMate, Sublime Text, etc, so the description here1960 jq uses the Oniguruma regular expression library, as do PHP,1961 Ruby, TextMate, Sublime Text, etc, so the description here1962 will focus on jq specifics.19631964 The jq regex filters are defined so that they can be used using1965 one of these patterns:19661967 STRING | FILTER( REGEX )1968 STRING | FILTER( REGEX; FLAGS )1969 STRING | FILTER( [REGEX] )1970 STRING | FILTER( [REGEX, FLAGS] )1967 STRING | FILTER(REGEX)1968 STRING | FILTER(REGEX; FLAGS)1969 STRING | FILTER([REGEX])1970 STRING | FILTER([REGEX, FLAGS])19711972 where:19731973 * STRING, REGEX and FLAGS are jq strings and subject to jq string interpolation;1974 * REGEX, after string interpolation, should be a valid PCRE regex;1974 * STRING, REGEX, and FLAGS are jq strings and subject to jq string interpolation;1975 * REGEX, after string interpolation, should be a valid regular expression;1976 * FILTER is one of `test`, `match`, or `capture`, as described below.19771978 FLAGS is a string consisting of one of more of the supported flags:19791980 * `g` - Global search (find all matches, not just the first)1981 * `i` - Case insensitive search1981 * `m` - Multi line mode ('.' will match newlines)1982 * `m` - Multi line mode (`.` will match newlines)1983 * `n` - Ignore empty matches1984 * `p` - Both s and m modes are enabled1984 * `s` - Single line mode ('^' -> '\A', '$' -> '\Z')1985 * `s` - Single line mode (`^` -> `\A`, `$` -> `\Z`)1986 * `l` - Find longest possible matches1987 * `x` - Extended regex format (ignore whitespace and comments)19881988 To match whitespace in an x pattern use an escape such as \s, e.g.1989 To match a whitespace with the `x` flag, use `\s`, e.g.19901990 * test( "a\\\\sb"; "x" )1991 jq -n '"a b" | test("a\\sb"; "x")'19921993 Note that certain flags may also be specified within REGEX, e.g.19941994 * jq -n '("test", "TEst", "teST", "TEST") | test( "(?i)te(?-i)st" )'1995 jq -n '("test", "TEst", "teST", "TEST") | test("(?i)te(?-i)st")'19961996 evaluates to: true, true, false, false.1997 evaluates to: `true`, `true`, `false`, `false`.19981999 entries:2000 - title: "`test(val)`, `test(regex; flags)`"2001 body: |
878 unmodified lines
modified:docs/content/manual/v1.6/manual.yml+16 added-15 removed
2198 unmodified lines
2199 input: '[{}, true, {"a":1}]'2200 output: ['[null, 1]']220122022203 - title: Regular expressions (PCRE)2203 - title: Regular expressions2204 body: |22052206 jq uses the Oniguruma regular expression library, as do php,2207 ruby, TextMate, Sublime Text, etc, so the description here2206 jq uses the Oniguruma regular expression library, as do PHP,2207 Ruby, TextMate, Sublime Text, etc, so the description here2208 will focus on jq specifics.22092210 The jq regex filters are defined so that they can be used using2211 one of these patterns:22122213 STRING | FILTER( REGEX )2214 STRING | FILTER( REGEX; FLAGS )2215 STRING | FILTER( [REGEX] )2216 STRING | FILTER( [REGEX, FLAGS] )2213 STRING | FILTER(REGEX)2214 STRING | FILTER(REGEX; FLAGS)2215 STRING | FILTER([REGEX])2216 STRING | FILTER([REGEX, FLAGS])22172218 where:22192219 * STRING, REGEX and FLAGS are jq strings and subject to jq string interpolation;2220 * REGEX, after string interpolation, should be a valid PCRE regex;2220 * STRING, REGEX, and FLAGS are jq strings and subject to jq string interpolation;2221 * REGEX, after string interpolation, should be a valid regular expression;2222 * FILTER is one of `test`, `match`, or `capture`, as described below.22232224 FLAGS is a string consisting of one of more of the supported flags:22252226 * `g` - Global search (find all matches, not just the first)2227 * `i` - Case insensitive search2227 * `m` - Multi line mode ('.' will match newlines)2228 * `m` - Multi line mode (`.` will match newlines)2229 * `n` - Ignore empty matches2230 * `p` - Both s and m modes are enabled2230 * `s` - Single line mode ('^' -> '\A', '$' -> '\Z')2231 * `s` - Single line mode (`^` -> `\A`, `$` -> `\Z`)2232 * `l` - Find longest possible matches2233 * `x` - Extended regex format (ignore whitespace and comments)22342234 To match whitespace in an x pattern use an escape such as \s, e.g.2235 To match a whitespace with the `x` flag, use `\s`, e.g.22362236 * test( "a\\\\sb"; "x" )2237 jq -n '"a b" | test("a\\sb"; "x")'22382239 Note that certain flags may also be specified within REGEX, e.g.22402240 * jq -n '("test", "TEst", "teST", "TEST") | test( "(?i)te(?-i)st" )'2241 jq -n '("test", "TEst", "teST", "TEST") | test("(?i)te(?-i)st")'22422242 evaluates to: true, true, false, false.2243 evaluates to: `true`, `true`, `false`, `false`.22442245 entries:2246 - title: "`test(val)`, `test(regex; flags)`"2247 body: |
1043 unmodified lines
modified:docs/content/manual/manual.yml+14 added-14 removed
2291 unmodified lines
2292 input: '[{}, true, {"a":1}]'2293 output: ['[null, 1]']229422952296 - title: Regular expressions (PCRE)2296 - title: Regular expressions2297 body: |22982299 jq uses the2300 [Oniguruma regular expression library](https://github.com/kkos/oniguruma/blob/master/doc/RE),2301 as do php, ruby, TextMate, Sublime Text, etc, so the2301 as do PHP, Ruby, TextMate, Sublime Text, etc, so the2302 description here will focus on jq specifics.23032304 The jq regex filters are defined so that they can be used using2305 one of these patterns:23062307 STRING | FILTER( REGEX )2308 STRING | FILTER( REGEX; FLAGS )2309 STRING | FILTER( [REGEX] )2310 STRING | FILTER( [REGEX, FLAGS] )2307 STRING | FILTER(REGEX)2308 STRING | FILTER(REGEX; FLAGS)2309 STRING | FILTER([REGEX])2310 STRING | FILTER([REGEX, FLAGS])23112312 where:23132314 * STRING, REGEX and FLAGS are jq strings and subject to jq string interpolation;2315 * REGEX, after string interpolation, should be a valid PCRE regex;2314 * STRING, REGEX, and FLAGS are jq strings and subject to jq string interpolation;2315 * REGEX, after string interpolation, should be a valid regular expression;2316 * FILTER is one of `test`, `match`, or `capture`, as described below.23172318 FLAGS is a string consisting of one of more of the supported flags:23192320 * `g` - Global search (find all matches, not just the first)2321 * `i` - Case insensitive search2322 * `m` - Multi line mode ('.' will match newlines)2322 * `m` - Multi line mode (`.` will match newlines)2323 * `n` - Ignore empty matches2324 * `p` - Both s and m modes are enabled2325 * `s` - Single line mode ('^' -> '\A', '$' -> '\Z')2325 * `s` - Single line mode (`^` -> `\A`, `$` -> `\Z`)2326 * `l` - Find longest possible matches2327 * `x` - Extended regex format (ignore whitespace and comments)23282329 To match whitespace in an x pattern use an escape such as \s, e.g.2329 To match a whitespace with the `x` flag, use `\s`, e.g.23302331 * test( "a\\\\sb"; "x" )2331 jq -n '"a b" | test("a\\sb"; "x")'23322333 Note that certain flags may also be specified within REGEX, e.g.23342335 * jq -n '("test", "TEst", "teST", "TEST") | test( "(?i)te(?-i)st" )'2335 jq -n '("test", "TEst", "teST", "TEST") | test("(?i)te(?-i)st")'23362337 evaluates to: true, true, false, false.2337 evaluates to: `true`, `true`, `false`, `false`.23382339 entries:2340 - title: "`test(val)`, `test(regex; flags)`"2341 body: |
1065 unmodified lines