New User -- regex question(s) ...

15 views
Skip to first unread message

LOSS PREVENTION

unread,
Mar 9, 2022, 4:45:36 AM3/9/22
to vim_use
 I have read, both http://www.vimregex.com/ -and- various sections of http://vimdoc.sourceforge.net/htmldoc/help.html. That said, I just can't figure out what I'm doing incorrectly. Please follow the live examples below:

1) Using \+ is not working for me in the following example -
Original 01 --> Theft Attempted or Completed Offense? Completed
Original 02 --> Theft Attempted or Completed Offense? Attempted
Broken --> %s/\v\s(Attempted or Completed Offense\?)\s(\u\w\+)\s/,\1,\2,/g

Working --> %s/\v\s(Attempted or Completed Offense\?)\s(\u\w.......)\s/,\1,\2,/g

I cannot find a written reason for this failure.

--Next--

%s/^M//g <--will work from the cmd-line, how do I do this from within a <script>.vim? I'm not understand the help files explanation on this; from a <script>.vim?

Respectfully.

Lifepillar

unread,
Mar 13, 2022, 9:53:26 AM3/13/22
to vim...@googlegroups.com
On 2022-03-09, LOSS PREVENTION <980bea...@gmail.com> wrote:
> I have read, both http://www.vimregex.com/ -and- various sections of
> http://vimdoc.sourceforge.net/htmldoc/help.html. That said, I just can't
> figure out what I'm doing incorrectly. Please follow the live examples
> below:
>
> 1) Using \+ is not working for me in the following example -
> Original 01 --> Theft Attempted or Completed Offense? Completed
> Original 02 --> Theft Attempted or Completed Offense? Attempted
> Broken --> %s/\v\s(Attempted or Completed Offense\?)\s(\u\w\+)\s/,\1,\2,/g

With \v, you should use + instead of \+.

> I cannot find a written reason for this failure.

I have taken a quick look at the help of \v and, in fact, I cannot find that
difference explained in the table. Maybe, it should.

> --Next--
>
> %s/^M//g <--will work from the cmd-line, how do I do this from within a
><script>.vim?

That is an ex command: it works in exactly the same way in a script.

Life.

Reply all
Reply to author
Forward
0 new messages