正则表达式 9. 替换分组使用
https://www.zybuluo.com/Zjmainstay/note/709093
9. 替换分组使用
需求:给源串每个链接加上http://www.zjmainstay.cn前缀 源串: <a id="link-1" href="/regexp-one">正则文章合集(All In One)</a> <a id="link-2" href="/my-regexp">正则入门教程</a> <a id="link-3" href="/deep-regexp">正则高级教程</a> <a id="link-4" href="/regexp-lookaround">正则环视详解</a> <a id="link-5" href="/php-curl">PHP cURL应用</a> 预期:替换得到 <a id="link-1" href="http://www.zjmainstay.cn/regexp-one">正则文章合集(All In One)</a> <a id="link-2" href="http://www.zjmainstay.cn/my-regexp">正则入门教程</a> <a id="link-3" href="http://www.zjmainstay.cn/deep-regexp">正则高级教程</a> <a id="link-4" href="http://www.zjmainstay.cn/regexp-lookaround">正则环视详解</a> <a id="link-5" href="http://www.zjmainstay.cn/php-curl">PHP cURL应用</a> 查找:(<a.*?href=")([^"]*) 替换:$1http://www.zjmainstay.cn$2
测试地址:http://regex.zjmainstay.cn/r/lNr1zM/1
(9.2)将每行数据格式化为一条SQL语句
需求:将每行特定格式数据格式化为SQL语句 源串: 1 2017-04-11 Zjmainstay 2 2017-04-12 Nobody 3 2017-04-13 Somebody 预期:替换得到 INSERT INTO table_log(`id`, `created_at`, `author`) values('1', '2017-04-11', 'Zjmainstay'); INSERT INTO table_log(`id`, `created_at`, `author`) values('2', '2017-04-12', 'Nobody'); INSERT INTO table_log(`id`, `created_at`, `author`) values('3', '2017-04-13', 'Somebody'); 查找:(\d+)\s+(\S+)\s+(\S+) 替换:INSERT INTO table_log(`id`, `created_at`, `author`) values('$1', '$2', '$3');
测试地址:http://regex.zjmainstay.cn/r/lxsLPK/1