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
Provenance
- Commit
2e5c3f4- Tree
737bd31- Author
itchyny <itchyny@cybozu.co.jp>- Committer
GitHub <noreply@github.com>- Parent
433b79d
3 files changed+46 added−44 removed
modified:docs/content/manual/v1.5/manual.yml+16 added-15 removed
1952 unmodified lines1953 input: '[{}, true, {"a":1}]'1954 output: ['[null, 1]']1955 1956 1957- - title: Regular expressions (PCRE)1957+ - title: Regular expressions1958 body: |1959 1960- 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.1963 1964 The jq regex filters are defined so that they can be used using1965 one of these patterns:1966 1967- 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])1971 1972 where:1973+1973- * 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.1977 1978 FLAGS is a string consisting of one of more of the supported flags:1979 1980 * `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)1988 1988- 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.1990 1990- * test( "a\\\\sb"; "x" )1991+ jq -n '"a b" | test("a\\sb"; "x")'1992 1993 Note that certain flags may also be specified within REGEX, e.g.1994 1994- * jq -n '("test", "TEst", "teST", "TEST") | test( "(?i)te(?-i)st" )'1995+ jq -n '("test", "TEst", "teST", "TEST") | test("(?i)te(?-i)st")'1996 1996- evaluates to: true, true, false, false.1997+ evaluates to: `true`, `true`, `false`, `false`.1998 1999 entries:2000 - title: "`test(val)`, `test(regex; flags)`"2001 body: |878 unmodified linesmodified:docs/content/manual/v1.6/manual.yml+16 added-15 removed
2198 unmodified lines2199 input: '[{}, true, {"a":1}]'2200 output: ['[null, 1]']2201 2202 2203- - title: Regular expressions (PCRE)2203+ - title: Regular expressions2204 body: |2205 2206- 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.2209 2210 The jq regex filters are defined so that they can be used using2211 one of these patterns:2212 2213- 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])2217 2218 where:2219+2219- * 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.2223 2224 FLAGS is a string consisting of one of more of the supported flags:2225 2226 * `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)2234 2234- 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.2236 2236- * test( "a\\\\sb"; "x" )2237+ jq -n '"a b" | test("a\\sb"; "x")'2238 2239 Note that certain flags may also be specified within REGEX, e.g.2240 2240- * jq -n '("test", "TEst", "teST", "TEST") | test( "(?i)te(?-i)st" )'2241+ jq -n '("test", "TEst", "teST", "TEST") | test("(?i)te(?-i)st")'2242 2242- evaluates to: true, true, false, false.2243+ evaluates to: `true`, `true`, `false`, `false`.2244 2245 entries:2246 - title: "`test(val)`, `test(regex; flags)`"2247 body: |1043 unmodified linesmodified:docs/content/manual/manual.yml+14 added-14 removed
2291 unmodified lines2292 input: '[{}, true, {"a":1}]'2293 output: ['[null, 1]']2294 2295 2296- - title: Regular expressions (PCRE)2296+ - title: Regular expressions2297 body: |2298 2299 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.2303 2304 The jq regex filters are defined so that they can be used using2305 one of these patterns:2306 2307- 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])2311 2312 where:2313 2314- * 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.2317 2318 FLAGS is a string consisting of one of more of the supported flags:2319 2320 * `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)2328 2329- 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.2330 2331- * test( "a\\\\sb"; "x" )2331+ jq -n '"a b" | test("a\\sb"; "x")'2332 2333 Note that certain flags may also be specified within REGEX, e.g.2334 2335- * jq -n '("test", "TEst", "teST", "TEST") | test( "(?i)te(?-i)st" )'2335+ jq -n '("test", "TEst", "teST", "TEST") | test("(?i)te(?-i)st")'2336 2337- evaluates to: true, true, false, false.2337+ evaluates to: `true`, `true`, `false`, `false`.2338 2339 entries:2340 - title: "`test(val)`, `test(regex; flags)`"2341 body: |1065 unmodified lines