Regular expressions: Difference between revisions
Content added Content deleted
No edit summary |
m (Changed over to headers) |
||
Line 5: | Line 5: | ||
* to substitute part of a string using a regular expression |
* to substitute part of a string using a regular expression |
||
== |
=={{header|AppleScript}}== |
||
[[Category:AppleScript]] |
|||
'''Libraries:''' [[Satimage.osax]] |
'''Libraries:''' [[Satimage.osax]] |
||
Line 66: | Line 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) |
'''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: | Line 84: | ||
// result is now "I am the modified string" |
// result is now "I am the modified string" |
||
== |
=={{header|JavaScript}}== |
||
[[Category:JavaScript]] |
|||
Test/Match |
Test/Match |
||
var subject = "Hello world!"; |
var subject = "Hello world!"; |
||
Line 112: | Line 109: | ||
var newSubject = subject.replace(re_PatternToMatch, "Replaced"); |
var newSubject = subject.replace(re_PatternToMatch, "Replaced"); |
||
== |
=={{header|Perl}}== |
||
[[Category:Perl]] |
|||
'''Interpreter:''' [[Perl]] v5.8.8 |
'''Interpreter:''' [[Perl]] v5.8.8 |
||
Line 151: | Line 147: | ||
$string =~ s/i/u/ig; # would change "I am a string" into "u am a strung" |
$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 |
'''Interpreter:''' [[PHP]] 5.2.0 |
||
Line 170: | Line 164: | ||
echo "Found 'a' and replace it with 'another', resulting in this string: $string\n"; |
echo "Found 'a' and replace it with 'another', resulting in this string: $string\n"; |
||
== |
=={{header|Python}}== |
||
[[Category:Python]] |
|||
'''Interpreter:''' [[Python]] 2.5 |
'''Interpreter:''' [[Python]] 2.5 |
||
Line 202: | Line 195: | ||
'''Note:''' re.match() and regex.match() imply a "^" at the beginning of the regular expression. re.search() and regex.search() do not. |
'''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 |
'i am a string' as str |
||
Line 216: | Line 208: | ||
str r/ a / another / print |
str r/ a / another / print |
||
== |
=={{header|Ruby}}== |
||
[[Category:Ruby]] |
|||
Test |
Test |
||
string="I am a string" |
string="I am a string" |
||
Line 236: | Line 227: | ||
end) |
end) |
||
== |
=={{header|Tcl}}== |
||
[[Category:Tcl]] |
|||
Test |
Test |
||
Line 255: | Line 245: | ||
puts [regsub -- { a } {I am a string} { another }] |
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. |
Toka's regular expression library allows for matching, but does not yet provide for replacing elements within strings. |