2012年12月31日月曜日

開発環境

『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-84312-225-5) の4章(JavaScriptのオブジェクト)練習問第4-2を解いてみる。

その他参考書籍

4-2.

コード(BBEdit)


var str = "The fun of functions is that they are functional.";
var replaced_str = str.replace(/\bfun\b/g, "power");
var result = "置換前: " + str + "\n置換後: " + replaced_str;
$('#pre0').text(result);




ちなみにPython3kの場合。

コード(BBEdit)

sample.py

#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

import re

str = "The fun of functions is that they are functional. fun"
replaced_str = re.sub(r"\bfun\b", "power", str)
print("置換前:{0} \n置換後:{1}".format(str, replaced_str))

入出力結果(Terminal)

$ ./sample.py
置換前:The fun of functions is that they are functional. fun 
置換後:The power of functions is that they are functional. power
$

0 コメント:

コメントを投稿