简体   繁体   中英

How do I find and replace certain text in Visual Studio Code regex?

So I'm editing some old Lua code I wrote, and I'm trying to optimize it. I made a bunch of mistakes like using table.insert() and :len() when I should've used the faster Table[#Table + 1] = _ and #String . I have the code pasted into my Visual Studio Code, and I want to quickly replace them all. I think I already have the find RegEx for the :len() , but I just don't know how to make it replace it with the same value, and I certainly am unsure on how to make the table.insert work.

.:len\\(\\) is what I have for my find RegEx on the code, but I don't know how I'm supposed to replace it while keeping the previous value. Can anyone help a complete idiot out? Thanks!

Not really too sure what you mean by "replace it but keep old value" perhaps you could give an example?

I'm guessing the problem is keeping the argument while replacing the outer syntax? In which case use sub str parens matching: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_parenthesized_substring_matches_2

eg table\\.insert\\(([\\s\\S\\r\\n]*?)\\) with new($1)

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