Tuesday, July 30, 2013

Re: Regexp help

On Tuesday, July 30, 2013 9:27:51 AM UTC-5, Erik Christiansen wrote:
> On 30.07.13 06:57, Ben Fritz wrote:
>
> > Maybe better using "very magic":
>
>
>
> Everything's better with \v ;-)
>
>

Yes. I occasionally edit portions of my .vimrc where I didn't used it, and wonder why.

>
> > \v<\d+>\.@!
>
>
>
> On the test line:
>
>
>
> 123 123.0 123. 456 0.123 .123 789
>
>

The OP specifically said that valid decimals are "in the form 1.0D0, or more precisely \d\+\.\d\+D\d\+" so I didn't try stuff like "123." or ".123".

But possibly as in the other thread we need to account for negative numbers?

>
> that regex also detects the fractional parts as integers, so it still
>
> needs a tweak. This seems to do it:
>
>
>
> /\v\.@<!<\d+>\.@!
>
>

Good. Even without the narrow constraints I assumed it's fairly easy to tweak to get it more correct.

For the OP, Erik added a negative look-behind (similar to the look-ahead my first response used but constraining what comes BEFORE instead). See :help /\@<!

>
> But even that finds 06 and 57 in 06:57. Whether they are desired
>
> integers may vary between use cases. Admittedly they'll probably only
>
> crop up in rare strings in a fortran program.
>

Good point...but these would be harder to guard against.

--
--
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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: