Created
July 15, 2014 06:03
-
-
Save ascendbruce/37fcb970db5a391b2132 to your computer and use it in GitHub Desktop.
gsub regex replace part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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