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

效果

相关推荐
曲幽7 小时前
FastAPI 身份验证总踩坑?这份 FastAPI Users “避坑指南”请收好
python·fastapi·web·jwt·oauth2·user·authentication
装不满的克莱因瓶7 小时前
掌握 RNN 与 LSTM 模型结构
人工智能·python·rnn·深度学习·神经网络·ai·lstm
何以解忧,唯有..7 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
金銀銅鐵7 小时前
用 Tkinter 实现简单的猜数字游戏
后端·python
copyer_xyf8 小时前
Python 模块与包的导入导出
前端·后端·python
ice8130331818 小时前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib
copyer_xyf8 小时前
Python venv 虚拟环境
前端·后端·python
林爷万福9 小时前
GitHub 开源光谱数据处理项目推荐
python·光纤光谱仪
copyer_xyf10 小时前
Python 如何同时做很多事:进程、线程、协程
前端·后端·python
Full Stack Developme10 小时前
Spring Bean 依赖注入
python·spring·log4j