Sunday, November 9, 2008

Recurring RegEx short list


Regular Expression>>Matches
[0-9]\.>>1.

Eclipse: Ctrl+F, w/ Regular Expressions

Find {100 in "{100,"asas"}, {200,"asas"}}.." and replace the number 100 with a string "" to get
{"100","asas"}, {"200","asas"}

Find: \{([0-9]+) .. () marks a group
Replace: \{"\1"
  .. \1 identifies the 1st marked group.. so the number matched is retained when replaced.

Find: ^\(.*\)
Replace: <span id="time_stamp">$0</span>
e.g,:
(10:42:59 AM) ..
<span id="time_stamp">(10:42:49 AM)</span>

Find: (A{2})(B{2})
Replace: $1, $2
e.g,:
AABB ..
AA, BB

(\b[a-z]{4}?:)(\s.*?$)
<span id="name">$1</span><span id="chat">$2</span>
e.g,:
AJ: ahoy!! there!!
<span id="name">AJ:</span><span id="chat"> ahoy!! there!!</span>


No comments: