简体   繁体   中英

How to use Regex to find a specific string between two special characters?

I`m currently migrating sql data between two forum systems (Woltlab Burning Board 2 -> MyBB 1.8).

I need to change the internal links from http://example.com/thread.php?threadid=XYZ to http://example.com/showthread.php?tid=ABC . Thread ID's will change between the two systems, so I'm not able to do a simple string replace.

I already catch all posts containing http://example.com/thread.php?threadid= . Now I need to get the unique ID into a variable. As the whole post-string can also contain external links (eg http://google.com ) I cant just catch Numbers before.

I would like to catch the Thread-ID from this string http://example.com/thread.php?threadid=XYZ , which is part of a bigger string (Forum Post). I guess Regex could be used for this.

Any help would be highly appreciated! Thanks!

In PowerShell, the following will capture the thread ID:

$URI = "http://example.com/thread.php?threadid=2438&Query=GetSomething?2345"
$tid = ($URI | select-string -pattern "threadid=(\d+)").matches.groups.value[1]
$tid

If there is no thread id to be captured, the $tid assignment will throw an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM