Regular expressions: Difference between revisions

Content deleted Content added
Langurmonkey (talk | contribs)
Aartaka (talk | contribs)
→‎{{header|ed}}: Expand on things
 
(4 intermediate revisions by 3 users not shown)
Line 825:
If a < 0 then result:= -a;
</pre>
 
=={{header|ed}}==
 
Ed <tt>s</tt> command is using regex for substitution, so the editor has built-in native support for regex.
 
<syntaxhighlight lang="sed">
# by Artyom Bologov
H
t0
1s/^.*string.*$/Ends with string/
2s/ a / another /
,p
Q
</syntaxhighlight>
 
{{out}}
 
<pre>$ed -s regex.input < regex.ed
Newline appended
Ends with string
This is another string</pre>
 
=={{header|Elixir}}==
Elixir allows pattern matching using the <code>~r</code> sigil.
Line 1,396 ⟶ 1,418:
 
Or...
<syntaxhighlight lang="langur">if val .x, .y = submatch(re/(abc+).+?(def)/, "somestring") { ... }</syntaxhighlight>
 
Or...
Line 2,019 ⟶ 2,041:
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>