Jump to content

Text between: Difference between revisions

Added AutoHotkey
m (Corrected a comment.)
(Added AutoHotkey)
Line 392:
end text_between
</lang>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>data =
(
Hello Rosetta Code world|Hello | world|
Hello Rosetta Code world|start| world|
Hello Rosetta Code world|Hello |end|
</div><div style=\"chinese\">你好嗎</div>|<div style=\"chinese\">|</div>|
<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">|<text>|<table>|
<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">|<table>|</table>|
The quick brown fox jumps over the lazy other fox|quick | fox|
One fish two fish red fish blue fish|fish | red|
FooBarBazFooBuxQuux|Foo|Foo|
)
result := ""
for i, line in StrSplit(data, "`n", "`r")
x := StrSplit(line, "|")
, result .= "text: " x.1 "`nstart: " x.2 "`tend: " x.3 "`noutput: " textBetween(x.1, x.2, x.3) "`n----`n"
MsgBox, 262144, , % result
return
 
textBetween(text, start, end){
RegExMatch(text,(start="start"?"^":"\Q" start "\E") "(.*?)" (end="end"?"$":"\Q" end "\E?"),m)
return m1
}</lang>
{{out}}
<pre>text: Hello Rosetta Code world
start: Hello end: world
output: Rosetta Code
----
text: Hello Rosetta Code world
start: start end: world
output: Hello Rosetta Code
----
text: Hello Rosetta Code world
start: Hello end: end
output: Rosetta Code world
----
text: </div><div style=\"chinese\">你好嗎</div>
start: <div style=\"chinese\"> end: </div>
output: 你好嗎
----
text: <text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">
start: <text> end: <table>
output: Hello <span>Rosetta Code</span> world</text>
----
text: <text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">
start: <table> end: </table>
output:
----
text: The quick brown fox jumps over the lazy other fox
start: quick end: fox
output: brown
----
text: One fish two fish red fish blue fish
start: fish end: red
output: two fish
----
text: FooBarBazFooBuxQuux
start: Foo end: Foo
output: BarBaz
----</pre>
 
=={{header|AWK}}==
299

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.