Javascript搜索和替换需要包含更多内容
Javascript search and replace need to incorporate more
这是我的搜索和替换。如何合并注释或警报来描述模式和输入的功能框?欢迎提出任何建议!
<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>
这是无效的javascript,如果您尝试在导入时加载此页面,控制台将抛出错误:
Uncaught SyntaxError: Unexpected reserved word
它看起来是一个Java类,除非使用jsp之类的技术,否则不会在浏览器中运行。
有一些库已经可以做这样的字符串了。例如,尝试字符串:http://stringjs.com/.然而,如果您想在整个页面上运行此操作,则需要解析更复杂的DOM(对字符串执行此操作要容易得多)。
对于使用输入,您应该更深入地研究html。有许多文本框和文本字段选项,您可以将它们绑定到javascript。
相关文章:
- Javascript搜索和替换需要包含更多内容
- 搜索包含值的json对象键,然后取消设置
- td:包含变量中的搜索字符串
- 在“加载更多”按钮函数中包含 JSON 数据
- 包含 2 个或更多对象的页面上的 JavaScript 设计模式
- 在二维数组中搜索比嵌套循环更有效的方法
- 搜索包含包含所需值的范围的数组
- 创建一个CSS下拉菜单,其中包含从搜索图标弹出的搜索框
- 用于Cordova应用程序的Javascript SQLite-使用参数搜索,其中字符串包含子字符串大小写insenst
- 如何使用javascript/jquery/c#搜索和选择包含特殊字符的文本
- 在包含多个单词的表中搜索
- PHPExcel搜索/返回单元格中包含特定值的所有行
- 如何更新单词列表中搜索框中包含用户键入内容的单词/字母数
- 在引导选择组件中的搜索不起作用,其中数据令牌包含所有数字;4730”;
- 如何执行一个包含更多 HREF 地址的链接属性
- 如果当前网址不包含位置搜索,请重定向到主页
- 如何计算某一列中包含JavaScript搜索词的所有TD
- Node.js错误日志包含更多信息
- 为什么new Date()返回字符串,但包含更多函数
- 如何突出显示包含2个或更多html元素的搜索结果