relpipe-data/examples-rename-groups-backreferences.xml
author František Kučera <franta-hg@frantovo.cz>
Tue, 05 Feb 2019 19:18:28 +0100
branchv_0
changeset 244 d4f401b5f90c
parent 241 relpipe-data/examples.xml@f71d300205b7
child 329 5bc2bb8b7946
permissions -rw-r--r--
examples: move each example to a separate page + add generated list of examples

<stránka
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
	
	<nadpis>Using relpipe-tr-sed with groups and backreferences</nadpis>
	<perex>sed-like substitution with regex groups and backreferences</perex>
	<m:pořadí-příkladu>00800</m:pořadí-příkladu>

	<text xmlns="http://www.w3.org/1999/xhtml">
	
		<p>
			This tool also support regex groups and backreferences. Thus we can use parts of the matched string in our replacement string:
		</p>
		
		<m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate r 1 a string "some string xxx_123 some zzz_456 other" \
	| relpipe-tr-sed 'r' 'a' '([a-z]{3})_([0-9]+)' '$2:$1' \
	| relpipe-out-tabular]]></m:pre>
		
		<p>Which would convert this:</p>
		<pre><![CDATA[r:
 ╭────────────────────────────────────────╮
 │ a                             (string) │
 ├────────────────────────────────────────┤
 │ some string xxx_123 some zzz_456 other │
 ╰────────────────────────────────────────╯
Record count: 1]]></pre>
		
		<p>into this:</p>
		<pre><![CDATA[r:
 ╭────────────────────────────────────────╮
 │ a                             (string) │
 ├────────────────────────────────────────┤
 │ some string 123:xxx some 456:zzz other │
 ╰────────────────────────────────────────╯
Record count: 1]]></pre>

		<p>
			If there were any other relations or attributes in the stream, they would be unaffected by this transformation,
			becase we specified <code>'r' 'a'</code> instead of some wider regular expression that would match more relations or attributes.
		</p>
		
	</text>

</stránka>