Regular expressions: Difference between revisions

m
Changed over to headers
No edit summary
m (Changed over to headers)
Line 5:
* to substitute part of a string using a regular expression
 
==[[{{header|AppleScript]]}}==
[[Category:AppleScript]]
'''Libraries:''' [[Satimage.osax]]
 
Line 66 ⟶ 65:
}
 
==[[{{header|Java]]}}==
[[Category:Java]]
'''Java info:''' java version "1.5.0_06", Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05), Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
 
Line 86 ⟶ 84:
// result is now "I am the modified string"
 
==[[{{header|JavaScript]]}}==
[[Category:JavaScript]]
Test/Match
var subject = "Hello world!";
Line 112 ⟶ 109:
var newSubject = subject.replace(re_PatternToMatch, "Replaced");
 
==[[{{header|Perl]]}}==
[[Category:Perl]]
 
'''Interpreter:''' [[Perl]] v5.8.8
Line 151 ⟶ 147:
$string =~ s/i/u/ig; # would change "I am a string" into "u am a strung"
 
==[[{{header|PHP]]}}==
 
[[Category:PHP]]
 
'''Interpreter:''' [[PHP]] 5.2.0
Line 170 ⟶ 164:
echo "Found 'a' and replace it with 'another', resulting in this string: $string\n";
 
==[[{{header|Python]]}}==
[[Category:Python]]
 
'''Interpreter:''' [[Python]] 2.5
Line 202 ⟶ 195:
'''Note:''' re.match() and regex.match() imply a "^" at the beginning of the regular expression. re.search() and regex.search() do not.
 
==[[{{header|Raven]]}}==
[[Category:Raven]]
 
'i am a string' as str
Line 216 ⟶ 208:
str r/ a / another / print
 
==[[{{header|Ruby]]}}==
[[Category:Ruby]]
Test
string="I am a string"
Line 236 ⟶ 227:
end)
 
==[[{{header|Tcl]]}}==
[[Category:Tcl]]
 
Test
Line 255 ⟶ 245:
puts [regsub -- { a } {I am a string} { another }]
 
==[[{{header|Toka]]=}}=
[[Category:Toka]]
 
Toka's regular expression library allows for matching, but does not yet provide for replacing elements within strings.
Anonymous user