使用 大模型快速生成-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>

效果

相关推荐
仙女修炼史5 分钟前
gradcam在yolo中的应用
人工智能·python·yolo
李可以量化44 分钟前
Redis Client 从了解到精通(六):redis-py 服务控制与状态监控辅助函数详解
python
李可以量化1 小时前
Redis Client 从了解到精通(六)下:redis-py 时间、库管理与持久化辅助函数详解
python
晓窗科技1 小时前
AI基座哪家好
大数据·人工智能·python
麻雀飞吧1 小时前
学量化:看到“近期工具推荐”时,先问工具要解决什么问题
人工智能·python
jayson.h1 小时前
python——pdf编辑
前端·python·pdf
聪明蛋子哟1 小时前
多智能体协作的三种模式:从群聊到分层,如何设计可扩展的Agent系统
后端·python·flask
labixiong2 小时前
button按钮原生开关弹窗,零 JS 搞定80%交互场景
前端·javascript·html
zlwool2 小时前
图纸管理选型:从变更频率到齐套率
java·前端·python·erp·设备erp·非标机械
一晌小贪欢2 小时前
python-第15天:Python 列表推导式
开发语言·python·excel·数据可视化·python办公