-2
這裏是我的搜索和替換我想出了。如何結合註釋或警報來描述輸入的模式和功能框?任何建議表示讚賞!Javascript搜索和替換需要合併更多
Uncaught SyntaxError: Unexpected reserved word
這似乎是一個Java類,它將無法運行:
<html>
<head>
<title> Search & Replace</title>
</head>
<body>
<script language="javascript">
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class StringReplace {
public static void main(String[] args) {
String source = "The quick blue bird flies over the brown baseball field.";
String find = "blue";
String replace = "brown";
//
// Compiles the given regular expression into a pattern
//
Pattern pattern = Pattern.compile(find);
//
// Creates a matcher that will match the given input against the pattern
//
Matcher matcher = pattern.matcher(source);
//
// Replaces every subsequence of the input sequence that matches the
// pattern with the given replacement string
//
String output = matcher.replaceAll(replace);
System.out.println("Source = " + source);
System.out.println("Output = " + output);
}
}
</script>
</body>
</html>
「Java」是「JavaScript」,因爲「火腿」是「倉鼠」。 – lxe