relpipe-data/examples-rename-groups-backreferences.xml
author František Kučera <franta-hg@frantovo.cz>
Sun, 06 Oct 2019 11:24:40 +0200
branchv_0
changeset 271 a19312ab9db7
parent 244 d4f401b5f90c
child 329 5bc2bb8b7946
permissions -rw-r--r--
examples: Sane software manifesto statistics using XMLTable/XPath

<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>