package com.smtscript.lib.regex; import java.util.regex.Pattern; import org.mozilla.javascript.Wrapper; import com.smtscript.run.ScriptRunScope; public class JSRegex { protected ScriptRunScope _parentScope; protected Pattern _pattern; public JSRegex(ScriptRunScope parentScope, Object pattern) throws Exception { if(pattern instanceof Wrapper) pattern = ((Wrapper)pattern).unwrap(); if(pattern instanceof String) _pattern = Pattern.compile((String)pattern); else throw new Exception("unsupper patten type : " + pattern.getClass().getName()); _parentScope = parentScope; } public ScriptRunScope __parentScope__() { return _parentScope; } public JSRegexMatcher matcher(String text) { return new JSRegexMatcher(this, _pattern.matcher(text)); } public String replace(String text, Object replace) throws Exception { return matcher(text).replace(replace); } }