Re: about submatch in VIM

2011-04-04 Thread David Ohlemacher
I have a couple of those books.  But I keep going back to my Programming 
Perl book (camel book).  It has a nice and succinct (~10 pages) 
explanation of regex. It's perlish, but close to many implementations 
including Boost's.


Boost's docs have a nice reference for the re syntax, but it wont teach 
you what they mean.

http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/boost_regex/syntax.html

-d

On 04/01/2011 07:11 PM, Tim Chase wrote:

On 04/01/2011 07:01 AM, Coiby wrote:

I will appreciate it if you recommend some books on such topic.

There are several books[1] and websites[2] regarding regular
expressions.  Popular books:

- Mastering Regular Expressions (published by O'Reilly)
- Regular Expression Cookbook (published by O'Reilly)
- Regular Expression Pocket Reference (published by O'Reilly)

Note that dialects  functionalities of regular expression vary
from engine-to-engine, so the underlying ideas remain the same,
but the implementations may differ superficially.

-tim


[1]
http://www.google.com/search?q=regular+expression+books

[2]
http://www.regular-expressions.info
seems pretty decent as a starting-point




--
David Ohlemacher
Senior Software Engineer
Scientific Solutions Inc.
99 Perimeter Rd Nashua New Hampshire 03063
603-880-3784

. o .
. . o
o o o

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


Re: about submatch in VIM

2011-04-01 Thread Coiby
Tim, thanks very much for your detailed reply!
I will appreciate it if you recommend some books on such topic.  

--
View this message in context: 
http://vim.1045645.n5.nabble.com/about-submatch-in-VIM-tp4273737p4275287.html
Sent from the Vim - General mailing list archive at Nabble.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


Re: about submatch in VIM

2011-04-01 Thread Tim Chase

On 04/01/2011 07:01 AM, Coiby wrote:

I will appreciate it if you recommend some books on such topic.


There are several books[1] and websites[2] regarding regular 
expressions.  Popular books:


- Mastering Regular Expressions (published by O'Reilly)
- Regular Expression Cookbook (published by O'Reilly)
- Regular Expression Pocket Reference (published by O'Reilly)

Note that dialects  functionalities of regular expression vary 
from engine-to-engine, so the underlying ideas remain the same, 
but the implementations may differ superficially.


-tim


[1]
http://www.google.com/search?q=regular+expression+books

[2]
http://www.regular-expressions.info
seems pretty decent as a starting-point


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


Re: about submatch in VIM

2011-03-31 Thread ZyX
Reply to message «about submatch in VIM», 
sent 21:10:08 01 April 2011, Friday
by Coiby:

`\=' must be the at the beginning of the replacement string, so you should use 
`\=\/.(submatch(1)+1)' (`-1' is `decrease', not `increase'). By the way, you 
could have used `\@=':
$s!/\@=[1-9]\+!\=submatch(0)+1!g

Original message:
 Hi, everyone!
 I want to increase the number in this format /ddd by one but also keep
 /.
 But the following command doesn't work:
 $s/\/\([1-9]\+\)/\/\=submatch(1)-1)/g
 Can anyone give a tip?
 Thanks!
 
 --
 View this message in context:
 http://vim.1045645.n5.nabble.com/about-submatch-in-VIM-tp4273737p4273737.h
 tml Sent from the Vim - General mailing list archive at Nabble.com.


signature.asc
Description: This is a digitally signed message part.


Re: about submatch in VIM

2011-03-31 Thread Tim Chase

On 03/31/2011 12:10 PM, Coiby wrote:

I want to increase the number in this format /ddd by one but also keep
/.
But the following command doesn't work:
$s/\/\([1-9]\+\)/\/\=submatch(1)-1)/g
Can anyone give a tip?


In addition to what ZyX's comments (particularly about the \= 
needing to be at the beginning of the replacement), I'd use the 
\zs to mark the beginning of what I want to replace (which also 
allows you to tidy up the regexp by not needing \(...\) wrapped 
around), and use an alternate delimiter to obviate escaping:


  :%s@/\zs[1-9]\+@\=submatch(0)-1@g

A few other things of note:

- the lack of 0 is suspicious, so I expect you mean

  [1-9][0-9]*  positive numbers
  [0-9]\+  non-negative numbers

- you say you want increase the number, but you subtract 1 from 
it (easy fix...just change - to +)


- your initial expression has an extra close-paren that doesn't 
seem to have a matching open-paren.  That may have been a mis-key 
when transcribing.



Hope that gives you both a solution and a bit of understanding 
regarding what it's doing.


-tim



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