简体   繁体   中英

Search a pattern and replace it with regex in database

In a database, I am trying to extract data and replace it with a different code.

The data looks like this (single line), it is ordered in sets of one (a.jpg) up to 8 (h.jpg). a, ab, abc, abcd, abcde, abcdef, abcdefg, abcdefgh.

[team url=\"//SITEURL/images/year/month/IMAGENAMEa.jpg\" style=\"meta_overlaid\" name=\"NAME 1\"]
[team url=\"//SITEURL/images/year/month/IMAGENAMEb.jpg\" style=\"meta_overlaid\" name=\"NAME 2\"]
[team url=\"//SITEURL/images/year/month/IMAGENAMEc.jpg\" style=\"meta_overlaid\" name=\"NAME 3\"]
[team url=\"//SITEURL/images/year/month/IMAGENAMEd.jpg\" style=\"meta_overlaid\" name=\"NAME 4\"]
[team url=\"//SITEURL/images/year/month/IMAGENAMEe.jpg\" style=\"meta_overlaid\" name=\"NAME 5\"]
[team url=\"//SITEURL/images/year/month/IMAGENAMEf.jpg\" style=\"meta_overlaid\" name=\"NAME 6\"]
[team url=\"//SITEURL/images/year/month/IMAGENAMEg.jpg\" style=\"meta_overlaid\" name=\"NAME 7\"]
[team url=\"//SITEURL/images/year/month/IMAGENAMEh.jpg\" style=\"meta_overlaid\" name=\"NAME 8\"]

With this, I was able to select a single block, thus group 1 and 3 is the required data.

\[team url=\\"(.+?)\\"(.+?)name=\\"(.+?)\\"(.*?)\]

If I wanted an abc pattern, extract data and replace it, the next one worked, but not if I needed abcd, abcde,... to abcdefgh.

Here, groups 1,3,5,7,9 and 11 are my required data.

\[team url=\\"(.+?)a\.jpg\\"(.+?)name=\\"(.+?)\\"(.*?)\]\[team url=\\"(.+?)b\.jpg\\"(.+?)name=\\"(.+?)\\"(.*?)\]\[team url=\\"(.+?)c\.jpg\\"(.+?)name=\\"(.+?)\\"(.*?)\]

I thought I could create a similar set for the other groups, but there seems to be a limit and Atom and Sublime Text stop searching.

There has to be a better way to search, group and extract, but I am lost.

Hope I was able to explain myself, thank you for your time and suggestions.

In Sublime Text, you have no limit for groups.

If you need backreferences after the ninth one, use ${10} , ${11} , etc.

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