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

效果

相关推荐
小白菜又菜31 分钟前
Leetcode 235. Lowest Common Ancestor of a Binary Search Tree
python·算法·leetcode
Omigeq33 分钟前
1.2.2 - 采样搜索算法(以RRT和RRT*为例) - Python运动规划库教程(Python Motion Planning)
开发语言·人工智能·python·机器人
凌云拓界36 分钟前
TypeWell全攻略(二):热力图渲染引擎,让键盘发光
前端·后端·python·计算机外设·交互·pyqt·数据可视化
小白菜又菜41 分钟前
Leetcode 234. Palindrome Linked List
python·算法·leetcode
恒云客1 小时前
python uv debug launch.json
数据库·python·json
Katecat996631 小时前
YOLO11-SEG-AFPN-P345改进采血装置检测与识别系统
python
q1234567890981 小时前
FNN sin predict
开发语言·python
先做个垃圾出来………2 小时前
Python字节串“b“前缀
开发语言·python
dreams_dream2 小时前
什么是迭代器和生成器
python