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

效果

相关推荐
星云穿梭16 分钟前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵31 分钟前
用 Pygame 实现 15 puzzle
python·数学·游戏
黄忠6 小时前
大模型之LangGraph技术体系
python·llm
hboot19 小时前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
用户8356290780511 天前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python
用户8356290780511 天前
用 Python 自动化 PowerPoint 演讲者备注添加
后端·python
黄忠1 天前
01-系统架构设计-LangGraph状态机与多源异构RAG
python
zzzzzz3101 天前
假如我是掘金管理员,我先给评论区装个'代码审查'系统
python·程序员·机器人
砍材农夫1 天前
python环境|conda安装和使用(2)
后端·python
程序员龙叔2 天前
编写高质量 Skill 系列 -- 如何设计需求分析与用例生成的 SKILL
自动化测试·软件测试·python·软件测试工程师·接口测试·性能测试·skill·ai测试