惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
The Cloudflare Blog
D
DataBreaches.Net
J
Java Code Geeks
G
Google Developers Blog
L
LangChain Blog
N
Netflix TechBlog - Medium
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
小众软件
小众软件
量子位
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
博客园_首页
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
腾讯CDC

正则表达式

增加一点动力学正则 求教,如何系统性的学习正则表达式? sigil 正则表达式疑问 editplus 中如何去掉空格 临门一脚,这个正则怎么匹配不上字符串啊? 正则表达式合集帖(希望本帖能存活十年以上) 正则如何完整匹配整个单词 请问 EM 正则如何在文章最前面添加一段话 求教,这个正则怎么写 /(\w*)*$/.test('aaa#')这个正则导致我们的页面炸了……不同语言居然不一样 这个可以用正则表达式做到吗?GPT 聊了半天了 [求助]如何利用正则表达式将文本或换行用 p 标签包裹起来 正则匹配,怎么匹配不定内容的成对的中间的内容呢? 正则表达式 locate --regex 'bin/(bz|gz|zip)'有没语法问题? 上下两行内容合并正则有办法能实现吗 正则表达式如何截取一个完整括号的内容 有对 posix-正则 有研究的吗?问下 editplus 求个全选正则忽略前面的符号及符号内的内容 各位老哥,正则怎么写能排除一个或多个特定的 IP,匹配剩余所有 IP(或者说是否可以实现) 使用正则.*ab.*搜索二进制文件(pdf 格式),搜不到 ab 但是.*a.*可以找到 a,除了 ab 还有别的正则写法么? 这个正则表达式怎么写,要么在开头,要么前面有空格 求助:正则获取 sql 语句中的表名 Safari 上不支持向后匹配的正则表达式,请教替代方法 正则表达式如何忽略子字符串中的内容 求助 nginx 的 rewrite,需求是把 http 流量转到 https 求大佬指点 iHateRegex 一个收录各种正则表达式的网站 请教一下,如何利用正则表达将 html 中在<p></p>之间的/筛选出来 ep 求一个数字和单位的正则 正则菜鸟求教
想请教一个正则表达式,这正则能做吗
f9EHtxE2UtX3fG3 · 2023-02-10 · via 正则表达式

背景

  • 想要一块代码中抽取出 函数返回值, 函数名 函数类型,用来编出 main 函数

想要的功能,这能用正则做吗?

  • 可以匹配 c++函数的 返回值类型、函数名、参数类型列表
  • 返回值类型、参数类型会有:
    • 类型 1:
      • int
      • char
      • string
      • TreeNode *
      • Node *
    • vector<类型 1>
    • vector<类型 1> &
    • vector<vector<类型 1>>
    • vector<vector<类型 1>> &

问了 OpenAI 感觉不太对,每次问结果都不一样

Here's a regular expression that matches the return value type, function name, and parameter type in C++:

(int|vector<int>|vector<vector<int>>|string|vector<string>|vector<vector<string>>|ListNode\*|vector<ListNode\*>|char|vector<char>|vector<vector<char>>|TreeNode\*|Node\*)\s(\w+)\((.*)\)
The regular expression uses the following components:

(int|vector<int>|vector<vector<int>>|string|vector<string>|vector<vector<string>>|ListNode\*|vector<ListNode\*>|char|vector<char>|vector<vector<char>>|TreeNode\*|Node\*) matches the return value type, which can be one of the specified types.

\s matches a whitespace character.

(\w+) matches the function name, which is one or more word characters.

\(.*\) matches the parameter list, which is zero or more characters enclosed in parentheses.

举个例子

vector<int> f(vector<int>& a, TreeNode *b, int d){

}

  • 提取类型为了初始化
    vector<int> arg1 = {};
    TreeNode * arg2 = new TreeNode(xxx);
    int arg3 = 0;
    vector<int> result = f(arg1, arg2, arg3);

如果不能做,那只能写代码硬匹配了?