python - How to combine/join regular string with regex result? -



python - How to combine/join regular string with regex result? -

so have simple code:

def modify_mysql_log(): #/var/log/mysql/mysql.log #change: queries f=open("../mysql/mysql.log") t=open("../mysql/mysql2.log","w") line in f: line=re.sub(r'query\s*select[a-za-z\s+\w_]*\'',random.choice(queries),line) t.write(line) f.close() t.close()

now trying want able replace line query found regular look regular expresion used search with, random.choice(queries) combined regular exression result. i've looked @ other re functions somehow cant see how that.

line=re.sub(r'regex', random.choice(queries), line)

this code homecoming string obtained replacing "leftmost non-overlapping occurrence" of regex random.choice(queries). if regex not found returning line.

if understand problem correctly, seek searching line regex , using string.replace(string_found_by_regex, random.choice(queries) + line)

python regex string substitution

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -