Regular expressions: Difference between revisions

PascalABC.NET
(PascalABC.NET)
 
Line 2,019:
I think that I am Nigel contains I am
I think that you are Nigel contains you are
</pre>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
begin
// text in tag (lazy quantification)
var s := '<tag>abc</tag> def <tag>ghi</tag>';
foreach var m in s.Matches('(?<=<tag>)(.*?)(?=</tag>)') do
Println(m.Value, m.Index);
// take words in parentheses
s := 'one two three four five';
Regex.Replace(s,'\w+','<$0>').Println;
end.
</syntaxhighlight>
{{out}}
<pre>
abc 5
ghi 24
<one> <two> <three> <four> <five>
</pre>
 
222

edits