On Friday, April 20, 2012 8:51:37 PM UTC+2, Ben Fritz wrote:
> On Friday, April 20, 2012 11:30:02 AM UTC-5, rameo wrote:
> > On Friday, April 20, 2012 5:52:37 PM UTC+2, Ben Fritz wrote:
> > > On Friday, April 20, 2012 2:45:28 AM UTC-5, rameo wrote:
> > > > 
> > > > After all these match() and matchend() problems, I'm trying to view if 
> > > > matches can be captured by using the submatch(0) and adding them to a 
> > > > register.
> > > > Isn't this a bit dangerous because you have to return the submatch (in 
> > > > order to left the buffertext unchanged)?
> > > > However I tested that it captures all matches whatever the regex is.
> > > 
> > > submatch() only works inside a substitute() call or inside a :substitute 
> > > command (:help sub-replace-expression). It says this explicitly in :help 
> > > submatch(). In the future, please read the help topics on the functions 
> > > you are using before posting to the list.
> > > 
> > > In order to use the matched text, you can try matchstr() or matchlist() 
> > > instead. Again, had you read the help for match(), you would have been 
> > > directed to these functions.
> > 
> > yes Ben,
> > What do you think that I haven't read the help?
> > I know that submatch() works only in a substitute command but that was not 
> > my question.
> > I asked if it is a bit dangerous to use submatch() to capture matches 
> > because it does a substitute in the text. However it seems to capture all, 
> > whatever regex.
> > 
> > And I've read also about match(), but not everything is so easy for me as 
> > it is for you as you are a longtime user ;)
> 
> My apologies, I must have misunderstood your question about submatch(). I 
> thought you had not read the help because:
> 
> 1. I thought you were trying to use submatch() with a match() or matchend() 
> call, since you did not mention using substitute()
> 2. You did not seem aware of the optional 4th argument to match() and 
> matchend() which is documented in the help
> 3. You did not seem aware of matchstr() or matchlist(), which are linked from 
> the help topic for match()
> 
> submatch() does not do any substitute by itself. It is as way to access a 
> captured group in the replace text for a regular expression applied using the 
> substitute() function, or the :substitute command, either of which can be 
> manipulated to not actually make any textual changes.

No problem.
ad 1) yes you're right I didn't mention it but I thought it was clear that I 
mentioned submatch() as alternative of match(),matchend()
ad 2) you're right. I was not aware of the 4th argument to match() and 
matchend()
ad 3) I know them. I often use matchstr().

I didn't know that submatch() doesn't do a substitute itself.
Yesterday I created a function which captures now what I want to capture using 
submatch() but I noted that the buffer is modified every time I capture the 
matches (using submatch()).

Btw.. thank you for your answers. I learn a lot of your replies.

-- 
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

Reply via email to