sql - 如何使用正则表达式在两个特殊字符之间查找特定字符串?
问题描述
我目前正在两个论坛系统(Woltlab Burning Board 2 -> MyBB 1.8)之间迁移 sql 数据。
我需要将内部链接从http://example.com/thread.php?threadid=XYZ更改 为http://example.com/showthread.php?tid=ABC。线程 ID 将在两个系统之间更改,因此我无法进行简单的字符串替换。
我已经捕获了所有包含http://example.com/thread.php?threadid=的帖子。现在我需要将唯一 ID 放入变量中。由于整个 post-string 还可以包含外部链接(例如http://google.com),所以我之前不能只捕获数字。
我想从这个字符串http://example.com/thread.php?threadid=XYZ中捕获 Thread-ID ,它是一个更大的字符串(论坛帖子)的一部分。我想 Regex 可以用于此。
任何帮助将不胜感激!谢谢!
解决方案
在 PowerShell 中,以下将捕获线程 ID:
$URI = "http://example.com/thread.php?threadid=2438&Query=GetSomething?2345"
$tid = ($URI | select-string -pattern "threadid=(\d+)").matches.groups.value[1]
$tid
如果没有要捕获的线程 id,$tid
分配将抛出错误。
推荐阅读
- swift - 从 Swift 在 Bash 终端中创建文件
- angular - Popover/tooltip ui bootstrap angular 6 under condition
- javascript - 如何在 JavaScript AJAX 调用中收集仅包含指定键的数组?
- sql - 如何使用 SQL(Oracle)从给定的数字中查找代码名称
- python - conda install 和 conda update 有什么区别?
- python - Python 请求以编程方式获取预先格式化为字典的开发工具表单数据
- sql - SQL:更新 GROUP BY 以包含基于另一列的最大值的值
- javascript - Mocha 测试未运行“try..finally”子句
- r - 在 R 中的 ggplot2 中向折线图添加第二个图例
- ios - 检测矩形时崩溃,Swift,iOS