Using non-greedy quantifiers with substitute()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using non-greedy quantifiers with substitute()

Felix Thibault
I'm having problems with a plugin and I've narrowed it down to one line. If I write:
echo substitute("#|\nmulti-line comment\n|#","#|.*|#","","g")


the substitution happens like expected. But if I use a non-greedy quantifier I get the original string unchanged
echo  substitute("#|\nmulti-line comment\n|#","#|.\{-}|#","","g")



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/dd3b2557-353c-4bb6-8f0e-19f566e0c4b2%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using non-greedy quantifiers with substitute()

John Little-4
You've used a double-quote string, which processes backslash characters, for the pattern. Either double the backslash, or use a single-quote string:

echo substitute("#|\nmulti-line comment\n|#",'#|.\{-}|#',"","g")

HTH, and regards,

John Little

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/ac338094-581e-4b28-9598-7da9a0160b40%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using non-greedy quantifiers with substitute()

Felix Thibault
Thank you so much- I had no idea about single quote strings.

On Mon, Mar 16, 2020 at 6:32 PM John Little <[hidden email]> wrote:
You've used a double-quote string, which processes backslash characters, for the pattern. Either double the backslash, or use a single-quote string:

echo substitute("#|\nmulti-line comment\n|#",'#|.\{-}|#',"","g")

HTH, and regards,

John Little

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/ac338094-581e-4b28-9598-7da9a0160b40%40googlegroups.com.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAGyWG1tQDmYLzzKYuPpfLkO8zdq3K_jvJ%3Dhwe3kXDrbAkQGHBw%40mail.gmail.com.