如何用空格替换所有出现的文本,无论大写锁定?
出现:" ksm" (有或没有大写字母锁定字母)到" k sm"
示例:
import gtk
from random import random
import numpy as np
from multiprocessing.pool import ThreadPool
import matplotlib.pyplot as plt
import matplotlib.animation as animation
#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
#from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas
class HelloWorld:
def __init__(self):
interface = gtk.Builder()
interface.add_from_file('interface.glade')
self.dialog1 = interface.get_object("dialog1")
self.label1 = interface.get_object("label1")
self.entry1 = interface.get_object("entry1")
self.button1 = interface.get_object("button1")
self.hbox1 = interface.get_object("hbox1")
self.fig, self.ax = plt.subplots()
self.X = [random() for x in range(10)]
self.Y = [random() for x in range(10)]
self.line, = self.ax.plot(self.X, self.Y)
self.canvas = FigureCanvas(self.fig)
# self.hbox1.add(self.canvas)
self.hbox1.pack_start(self.canvas)
interface.connect_signals(self)
self.dialog1.show_all()
def gtk_widget_destroy(self, widget):
gtk.main_quit()
def on_button1_clicked(self, widget):
name = self.entry1.get_text()
self.label1.set_text("Hello " + name)
self.ani = animation.FuncAnimation(self.fig, self.animate, np.arange(1, 200), init_func=self.init, interval=25, blit=True)
'''
pool = ThreadPool(processes=1)
async_result = pool.apply_async(animation.FuncAnimation, args=(self.fig, self.animate, np.arange(1, 200)), kwds={'init_func':self.init, 'interval':25, 'blit':True} )
self.ani = async_result.get()
'''
plt.show()
def animate(self, i):
# Read XX and YY from a file or whateve
XX = [random() for x in range(10)] # just as an example
YY = [random() for x in range(10)] # just as an example
self.line.set_xdata( XX )
self.line.set_ydata( YY )
return self.line,
def init(self):
self.line.set_ydata(np.ma.array(self.X, mask=True))
return self.line,
if __name__ == "__main__":
HelloWorld()
gtk.main()
答案 0 :(得分:2)
您可以在preg_replace
regex
/((bulk)(sms))/i
说明:使用bulksms
字符串的i
修饰符捕获字case-insensitive
$str = "bulksms bulKsms bulKSMS BulkSMS BULKSMS bulkSMS(dot)com bulksms´s BulkSMSs";
echo preg_replace("/((bulk)(sms))/i","$2 $3",$str);
答案 1 :(得分:0)
即使你的问题不是很具体,我想你想在php中这样做,所以你可以使用preg_replace_callback:
$strinToParse = 'test: bulksms bulKsms bulKSMS BulkSMS BULKSMS bulkSMS(dot)com bulksms´s BulkSMSs';
$string = preg_replace_callback('/(ksm)/i', function ($matches) { return 'k sm';}, $strinToParse);
将返回
测试:批量sms批量短信散装smS批量smS BULK smS批量smS(点)com批量短信散装smS