Skip to content

Instantly share code, notes, and snippets.

Created April 8, 2011 23:28
Show Gist options
  • Save anonymous/9e2b4b587ca507e7296e to your computer and use it in GitHub Desktop.
Save anonymous/9e2b4b587ca507e7296e to your computer and use it in GitHub Desktop.
package
{
import flash.display.Sprite;
public class Main extends Sprite
{
public function Main()
{
const ELEMENTS:String = "Na Sb"; // 元素記号を半角スペース区切りで並べる
var str:String = "[Na(cryptand 222)]3Sb7";
str = str.replace(/(?<=])(\d+)/g, "<sub>$1</sub>");
for each (var element:String in ELEMENTS.split(" "))
{
str = str.replace(new RegExp("(?<=" + element + ")(\\d+)", "g"), "<sub>$1</sub>");
}
trace(str);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment