使用 大模型快速生成-jsToJava 的正则表达式离线版本的简单html页面

注意:需求要描述清楚-提高程序员的工作效率

代码

html 复制代码
<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    <title>正则表达式转换工具:JS to Java</title>  
</head>  
<body>  
    <h1>正则表达式转换工具:JS to Java</h1>  
    <p>输入您的JavaScript正则表达式(不包含标志):</p>  
    <textarea id="jsRegexInput" rows="4" cols="50"></textarea>  
    <button onclick="convertRegex()">转换正则表达式</button>  
    <p>转换后的Java正则表达式 (可能需要进一步调整):</p>  
    <textarea id="javaRegexOutput" rows="4" cols="50" readonly></textarea>  
  
    <script>  
        function convertRegex() {  
            const jsRegexInput = document.getElementById('jsRegexInput').value;  
            let javaRegex = jsRegexInput;  
  
            // 处理可能需要在Java中转义的字符  
            javaRegex = javaRegex.replace(/\\/g, "\\\\"); // 转义反斜杠  
            javaRegex = javaRegex.replace(/'/g, "\\'"); // 转义单引号(如果原始JS正则表达式包含)  
            javaRegex = javaRegex.replace(/"/g, "\\\""); // 转义双引号(如果原始JS正则表达式包含)  
  
            // 在Java中,正则表达式通常被双引号包围,并且可能需要用Pattern.compile来编译  
            javaRegex = `Pattern.compile("${javaRegex}")`;  
  
            // 输出转换后的Java正则表达式  
            document.getElementById('javaRegexOutput').value = javaRegex;  
        }  
    </script>  
</body>  
</html>

效果

相关推荐
智能体与具身智能20 小时前
TVA具身智能的概念、架构与应用(19)
人工智能·python·具身智能
2601_9622946121 小时前
python中range函数怎么用
python·for循环·可迭代对象·range函数·整数列表
青 春 记 忆1 天前
零基础入门python70:Docker Compose 编排完整后端
python·后端开发
新时代牛马1 天前
字符设备驱动完整篇:从 cdev_add、file_operations 到chrdev_open 与排障
开发语言·python
白山编程大哥1 天前
Java OutputStreamWriter 详解:从字符到字节的桥梁
java·开发语言·python
xy34531 天前
axure9.0 如何打造一个计时器(简单版)
前端·ui·html·axure·原型·产品设计
IMPYLH1 天前
HTML 的 <pre> 元素
前端·javascript·html
落羽的落羽1 天前
【AI】快速理解AI应用的相关名词概念
linux·c++·人工智能·python·计算机网络·算法
Chasing__Dreams1 天前
大模型应用开发--13--RAG 查询优化策略
python
“AI国潮设计-小江”1 天前
《Python实战 | SDXL大模型批量生成“英歌舞海浪”蛋糕IP,附核心Prompt控制代码与IP授权变现思路》
人工智能·python·prompt·aigc