Skip to content

Instantly share code, notes, and snippets.

@ascendbruce
Created July 15, 2014 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ascendbruce/37fcb970db5a391b2132 to your computer and use it in GitHub Desktop.
Save ascendbruce/37fcb970db5a391b2132 to your computer and use it in GitHub Desktop.
gsub regex replace part
content = "這是標題之前<h1>這是標題</h1>這是標題之後"
content.gsub(/\<h1(.*)\<\/h1\>/, '<h2\1</h2>')
=> "這是標題之前<h2>這是標題</h2>這是標題之後"
# 重點在於 match 時的 () 包起來的東西變成 \1 (但必須用單引號 '' 才有效)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment