Anonymous user
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
==
'''Libraries:''' [[Satimage.osax]]
Line 66 ⟶ 65:
}
==
'''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"
==
Test/Match
var subject = "Hello world!";
Line 112 ⟶ 109:
var newSubject = subject.replace(re_PatternToMatch, "Replaced");
==
'''Interpreter:''' [[Perl]] v5.8.8
Line 151 ⟶ 147:
$string =~ s/i/u/ig; # would change "I am a string" into "u am a strung"
==
'''Interpreter:''' [[PHP]] 5.2.0
Line 170 ⟶ 164:
echo "Found 'a' and replace it with 'another', resulting in this string: $string\n";
==
'''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.
==
'i am a string' as str
Line 216 ⟶ 208:
str r/ a / another / print
==
Test
string="I am a string"
Line 236 ⟶ 227:
end)
==
Test
Line 255 ⟶ 245:
puts [regsub -- { a } {I am a string} { another }]
==
Toka's regular expression library allows for matching, but does not yet provide for replacing elements within strings.
|