简体   繁体   中英

wp-cli search-replace not replace when using regex

I'm using the following command to remove [download id="XXXX"] patterns:

wp search-replace '\[download id="([0-9]+)"]' ' ' wp_posts --regex --regex-flags='i'

But it didn't replace anything.

Try the following:

wp search-replace '\[download id="([0-9]+)"\]' ' ' wp_posts --regex --regex-flags='i'

You escaped the square opening bracket, however, left the closing one without a backslash. The regex will fail because you closed a character group that was never opened.

Fixed!

wp search-replace '\[download id=\"([0-9]+)\"\]' ' ' wp_posts --regex --regex-flags='i'

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