regex variable

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

regex variable

shawn wilson
Is there a way of using a variable in a regex?

I'm constantly looking for the first octet of IP addresses, so I do:
/[^0-9\.]10\.

What I've been doing is hitting / and up arrow and then edit but if I
could store [^0-9\.] in something easily accessed, that would save
some time.

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Gautier DI FOLCO
2013/7/18 shawn wilson <[hidden email]>
Is there a way of using a variable in a regex?

I'm constantly looking for the first octet of IP addresses, so I do:
/[^0-9\.]10\.

What I've been doing is hitting / and up arrow and then edit but if I
could store [^0-9\.] in something easily accessed, that would save
some time.

Fortunately :)

for example:
:%s/\([^0-9\.]\)10\./\1/g

will only leave the first octet of IP addresses.

Regards.

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Marcin Szamotulski
In reply to this post by shawn wilson
On 09:42 Thu 18 Jul     , shawn wilson wrote:
> Is there a way of using a variable in a regex?
>
> I'm constantly looking for the first octet of IP addresses, so I do:
> /[^0-9\.]10\.
>
> What I've been doing is hitting / and up arrow and then edit but if I
> could store [^0-9\.] in something easily accessed, that would save
> some time.

Hi,

You can set:
:let ip='[^0-9\.]
and then use:
/^r=ip<cr>
(i.i. hit '/' for search, the CTRL+r, then =, then write the variable name and
then hit <cr>).  See ":help c^r=" for the expression register.

But maybe more useful is make a mapping:
cmap <Leader>i ['0-9\.]

or even better allow for this map only in search:
cmap <expr> <Leader>i (getcmdtype() == '/' ? "['0-9\\.]" : '\i')

I assumed here that your <Leader> key is set to '\', otherwise you just
have to modify the '\i'.

Best regards,
Marcin

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

shawn wilson
In reply to this post by Gautier DI FOLCO
On Thu, Jul 18, 2013 at 9:50 AM, Gautier DI FOLCO
<[hidden email]> wrote:
> 2013/7/18 shawn wilson <[hidden email]>

>> What I've been doing is hitting / and up arrow and then edit but if I
>> could store [^0-9\.] in something easily accessed, that would save
>> some time.
>

>
> for example:
> :%s/\([^0-9\.]\)10\./\1/g
>

Uh, I guess I wasn't clear - I have no issues writing regexes - the
goal is to stop typing the same thing over and over again. I figure
maybe there's a way to access variables within the interpreter or
match() or maybe run a macro within one of them.

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

shawn wilson
In reply to this post by Marcin Szamotulski
Sweet, didn't know about C+r - that works. I'll look more into the
leader stuff (which'll probably work better) later. Thanks

On Thu, Jul 18, 2013 at 9:55 AM, Marcin Szamotulski <[hidden email]> wrote:

> On 09:42 Thu 18 Jul     , shawn wilson wrote:
>> Is there a way of using a variable in a regex?
>>
>> I'm constantly looking for the first octet of IP addresses, so I do:
>> /[^0-9\.]10\.
>>
>> What I've been doing is hitting / and up arrow and then edit but if I
>> could store [^0-9\.] in something easily accessed, that would save
>> some time.
>
> Hi,
>
> You can set:
> :let ip='[^0-9\.]
> and then use:
> /^r=ip<cr>
> (i.i. hit '/' for search, the CTRL+r, then =, then write the variable name and
> then hit <cr>).  See ":help c^r=" for the expression register.
>
> But maybe more useful is make a mapping:
> cmap <Leader>i ['0-9\.]
>
> or even better allow for this map only in search:
> cmap <expr> <Leader>i (getcmdtype() == '/' ? "['0-9\\.]" : '\i')
>
> I assumed here that your <Leader> key is set to '\', otherwise you just
> have to modify the '\i'.
>
> Best regards,
> Marcin
>
> --
> --
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Marcin Szamotulski
On 10:06 Thu 18 Jul     , shawn wilson wrote:

> Sweet, didn't know about C+r - that works. I'll look more into the
> leader stuff (which'll probably work better) later. Thanks
> > --
> > --
> > 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].
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >

As written in the above list header added to every message, please do
not top-post.  Bottom-posting is much nicer for people who want to
follow a thread discussion.

Regards,
Marcin

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Bee
Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Bee
In reply to this post by shawn wilson
On Thursday, July 18, 2013 6:42:06 AM UTC-7, shawn wilson wrote:

> Is there a way of using a variable in a regex?
>
>
>
> I'm constantly looking for the first octet of IP addresses, so I do:
>
> /[^0-9\.]10\.
>
>
>
> What I've been doing is hitting / and up arrow and then edit but if I
>
> could store [^0-9\.] in something easily accessed, that would save
>
> some time.

Different approach:

:help q/

List recent searches, allowing you to select one, and if need edit.

Similarly :help q:

List recent commands.

Bill

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Lech Lorens
In reply to this post by shawn wilson
On Thursday, July 18, 2013 3:42:06 PM UTC+2, shawn wilson wrote:

> Is there a way of using a variable in a regex?
>
> I'm constantly looking for the first octet of IP addresses, so I do:
> /[^0-9\.]10\.
>
>
>
> What I've been doing is hitting / and up arrow and then edit but if I
> could store [^0-9\.] in something easily accessed, that would save
> some time.

Slightly off-topic, but wanted to make you aware that [^\.] matches anything that isn't a dot AND IS NOT A BACKSLASH. IOW backslash is not escaping the dot inside the [] range.

Cheers,
Lech

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Benjamin Fritz
On Thursday, July 18, 2013 3:51:01 PM UTC-5, Lech Lorens wrote:
> On Thursday, July 18, 2013 3:42:06 PM UTC+2, shawn wilson wrote:
> >
> > I'm constantly looking for the first octet of IP addresses, so I do:
> > /[^0-9\.]10\.
> >
>
> Slightly off-topic, but wanted to make you aware that [^\.] matches anything that isn't a dot AND IS NOT A BACKSLASH. IOW backslash is not escaping the dot inside the [] range.
>

And furthermore the . doesn't NEED escaping inside the [] range.

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

shawn wilson


On Jul 18, 2013 5:54 PM, "Ben Fritz" <[hidden email]> wrote:
>
> On Thursday, July 18, 2013 3:51:01 PM UTC-5, Lech Lorens wrote:
> > On Thursday, July 18, 2013 3:42:06 PM UTC+2, shawn wilson wrote:
> > >
> > > I'm constantly looking for the first octet of IP addresses, so I do:
> > > /[^0-9\.]10\.
> > >
> >
> > Slightly off-topic, but wanted to make you aware that [^\.] matches anything that isn't a dot AND IS NOT A BACKSLASH. IOW backslash is not escaping the dot inside the [] range.
> >
>
> And furthermore the . doesn't NEED escaping inside the [] range.
>

This is probably a feature request but I really do hate the regex engine and would love to swap it out. Is there / can there be a compile time option to use a different engine?

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Tony Mechelynck
On 07/19/13 03:34, shawn wilson wrote:

>
> On Jul 18, 2013 5:54 PM, "Ben Fritz" <[hidden email]
> <mailto:[hidden email]>> wrote:
>  >
>  > On Thursday, July 18, 2013 3:51:01 PM UTC-5, Lech Lorens wrote:
>  > > On Thursday, July 18, 2013 3:42:06 PM UTC+2, shawn wilson wrote:
>  > > >
>  > > > I'm constantly looking for the first octet of IP addresses, so I do:
>  > > > /[^0-9\.]10\.
>  > > >
>  > >
>  > > Slightly off-topic, but wanted to make you aware that [^\.] matches
> anything that isn't a dot AND IS NOT A BACKSLASH. IOW backslash is not
> escaping the dot inside the [] range.
>  > >
>  >
>  > And furthermore the . doesn't NEED escaping inside the [] range.
>  >
>
> This is probably a feature request but I really do hate the regex engine
> and would love to swap it out. Is there / can there be a compile time
> option to use a different engine?

There is a runtime option to disable the new engine in favour of the old
one — or vice-versa. See :help 'regexpengine'

--
The only difference in the game of love over the last few thousand years
is that they've changed trumps from clubs to diamonds.
                -- The Indianapolis Star

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

RE: regex variable

JohnBeckett
In reply to this post by shawn wilson
shawn wilson wrote:
> This is probably a feature request but I really do hate the
> regex engine and would love to swap it out. Is there / can
> there be a compile time option to use a different engine?

No (I assume you want different regex syntax, probably PCRE).

Tony's post is talking about a new Vim regex engine intended to
be fully compatible with the old syntax, but faster.

Like Vim's scripting language, Vim's regex syntax makes a lot of
sense for editing text because they provide procedures that
often work in an optimum way.

John


--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

RE: regex variable

shawn wilson


On Jul 18, 2013 11:48 PM, "John Beckett" <[hidden email]> wrote:
>
> shawn wilson wrote:
> > This is probably a feature request but I really do hate the
> > regex engine and would love to swap it out. Is there / can
> > there be a compile time option to use a different engine?
>
> No (I assume you want different regex syntax, probably PCRE).
>

libpcre would be fine, yes. Or the library that Ruby uses - either way.

> Tony's post is talking about a new Vim regex engine intended to
> be fully compatible with the old syntax, but faster.
>

Though this means there's already code for choosing between engines which is good.

> Like Vim's scripting language, Vim's regex syntax makes a lot of
> sense for editing text because they provide procedures that
> often work in an optimum way.
>

Yeah, it looks like sed's syntax. If I'm used to writing things one way (say in code) and then hit '/' to do a similar thing inside my editor, switching mindset constantly makes me loose my thought (generally what happens) or make stupid errors like earlier in this thread.

I guess this should be a feature request then?

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

RE: regex variable

JohnBeckett
shawn wilson wrote:
> libpcre would be fine, yes. Or the library that Ruby uses -
> either way.
> ...
> I guess this should be a feature request then?

Vim is strongly attached to compatibility, and is immensely
complex. I would not bother requesting a new regex syntax
because it won't happen.

John


--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Vim's regex engine. [Was: regex variable]

Erik Christiansen
In reply to this post by shawn wilson
On 18.07.13 21:34, shawn wilson wrote:
> This is probably a feature request but I really do hate the regex engine
> and would love to swap it out. Is there / can there be a compile time
> option to use a different engine?

Granted, vim's obscurely parochial regex engine has for many years been
the one great failing in an otherwise stunningly good utility. But now
it has the \v regex prefix to provide a very good simulation of posix
EREs, qualifying that mode as "modern regex"¹.

It does seem ludicrous to be afflicted by a different regex dialect in
each tool one uses, especially when awk, mutt, egrep (or grep -E), sed
-r, vim with the \v prefix, lex (OK, it also has extensions), and other
*nix tools _all_ use modern posix EREs, allowing users to move
seamlessly between them, without incurring a brain hernia. EREs also
don't suffer from the backslash storm which afflicts obsolete REs.

Is there anything additional about vim's regex engine which troubles you?

Does the new regex engine not address any of those concerns?
(I freely admit to not having tried it myself yet, so cannot say what
benefits it might have brought.)

Incidentally, a number of years ago, I compiled vim with another regex
suite, and the resulting EREs worked beautifully - except that vim's
help broke. In retrospect, I guess that new helptags might have fixed
that. In any event, roll-your-own-regex-suite didn't take long, AFAIR,
comprising mainly some wrapper functions to handle the slightly
different function interface.

Erik

¹ See `man 7 regex`

--
"I am sorry for the length of this letter, but I did not have the time
to write a short one"
                     -  Blaise Pascal (in 1657), and later, Mark Twain.

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


BPJ
Reply | Threaded
Open this post in threaded view
|

Re: regex variable

BPJ
In reply to this post by shawn wilson
2013-07-19 09:59, shawn wilson skrev:

> On Jul 18, 2013 11:48 PM, "John Beckett" <[hidden email]> wrote:
>>
>> shawn wilson wrote:
>>> This is probably a feature request but I really do hate the
>>> regex engine and would love to swap it out. Is there / can
>>> there be a compile time option to use a different engine?
>>
>> No (I assume you want different regex syntax, probably PCRE).
>>
>
> libpcre would be fine, yes. Or the library that Ruby uses - either way.

> Yeah, it looks like sed's syntax. If I'm used to writing things one way
> (say in code) and then hit '/' to do a similar thing inside my editor,
> switching mindset constantly makes me loose my thought (generally what
> happens) or make stupid errors like earlier in this thread.

I feel the same sometimes, as I code Perl in Vim on a daily
basis, but Vim's (old) regex engine/syntax actually allows useful
things which are impossible or hard inn Perl, not only the other
way around. And I can always filter through a perl oneliner if I
want to use perl's regex engine. Can't you do the same with Ruby?
Vim regexes come closer to Perl's if you use of \v and so that
ought to bring you closer to PCRE too unless the "PC" is now only
an historical leftover (I haven't looked at the specs in a long
time, but hey) The only thing I regularly miss in Vim regexes is
\Q...\E. \V...\v comes close, although you still have to escape
your backslashes under \V.

So I guess I should file a feature request for support of \Q,
although someone probably has already...

/bpj

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Nikolay Aleksandrovich Pavlov


On Jul 19, 2013 5:49 PM, "BPJ" <[hidden email]> wrote:
>
> 2013-07-19 09:59, shawn wilson skrev:
>
>> On Jul 18, 2013 11:48 PM, "John Beckett" <[hidden email]> wrote:
>>>
>>>
>>> shawn wilson wrote:
>>>>
>>>> This is probably a feature request but I really do hate the
>>>> regex engine and would love to swap it out. Is there / can
>>>> there be a compile time option to use a different engine?
>>>
>>>
>>> No (I assume you want different regex syntax, probably PCRE).
>>>
>>
>> libpcre would be fine, yes. Or the library that Ruby uses - either way.
>
>
>> Yeah, it looks like sed's syntax. If I'm used to writing things one way
>> (say in code) and then hit '/' to do a similar thing inside my editor,
>> switching mindset constantly makes me loose my thought (generally what
>> happens) or make stupid errors like earlier in this thread.
>
>
> I feel the same sometimes, as I code Perl in Vim on a daily
> basis, but Vim's (old) regex engine/syntax actually allows useful
> things which are impossible or hard inn Perl, not only the other
> way around. And I can always filter through a perl oneliner if I
> want to use perl's regex engine. Can't you do the same with Ruby?
> Vim regexes come closer to Perl's if you use of \v and so that
> ought to bring you closer to PCRE too unless the "PC" is now only
> an historical leftover (I haven't looked at the specs in a long
> time, but hey) The only thing I regularly miss in Vim regexes is
> \Q...\E. \V...\v comes close, although you still have to escape
> your backslashes under \V.
>
> So I guess I should file a feature request for support of \Q,
> although someone probably has already...

To have this a way to embed variable is needed in first place. Otherwise you would need to escape \E which can only be done with a more complex (compared to escape()) substitute() call or a new function. AFAIR embedding variables was indeed requested.

The thing I constantly miss in vim RE engine is unicode and locales support.

> /bpj
>
>
> --
> --
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: regex variable

Benjamin Fritz
In reply to this post by BPJ
On Friday, July 19, 2013 8:49:34 AM UTC-5, BPJ wrote:

> 2013-07-19 09:59, shawn wilson skrev:
>
> > On Jul 18, 2013 11:48 PM, "John Beckett" <[hidden email]> wrote:
>
> >>
>
> >> shawn wilson wrote:
>
> >>> This is probably a feature request but I really do hate the
>
> >>> regex engine and would love to swap it out. Is there / can
>
> >>> there be a compile time option to use a different engine?
>
>
> I can always filter through a perl oneliner if I
>
> want to use perl's regex engine. Can't you do the same with Ruby?
>

For searching it's not possible to use a different syntax, but you can easily do it for substitution via :perldo, :rubydo, :luado, etc. That is, if you have your Vim compiled with support for your language of choice.

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: regex variable

shawn wilson
Just to be clear, I mentioned Ruby because don't like libpcre as much
and haven't used ruby enough for Oniguruma
(http://www.geocities.jp/kosako3/oniguruma/) to piss me off and afaik,
there would be no detatching perl's regex engine from perl. So it was
more of a comment of "I know these exist, would it be a good thing to
have and a decent feature request to have the ability to compile other
regex eingines in".

On Fri, Jul 19, 2013 at 10:02 AM, Ben Fritz <[hidden email]> wrote:

>
> For searching it's not possible to use a different syntax, but you can easily do it for substitution via :perldo, :rubydo, :luado, etc. That is, if you have your Vim compiled with support for your language of choice.
>

That's awesome, no more dropping out of vim to do a perl -ne. Not what
I'm looking for here, but awesome none-the-less.

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


BPJ
Reply | Threaded
Open this post in threaded view
|

Re: regex variable

BPJ
In reply to this post by Nikolay Aleksandrovich Pavlov
2013-07-19 16:00, Nikolay Pavlov skrev:

> On Jul 19, 2013 5:49 PM, "BPJ" <[hidden email]> wrote:
>>
>> 2013-07-19 09:59, shawn wilson skrev:
>>
>>> On Jul 18, 2013 11:48 PM, "John Beckett" <[hidden email]> wrote:
>>>>
>>>>
>>>> shawn wilson wrote:
>>>>>
>>>>> This is probably a feature request but I really do hate the
>>>>> regex engine and would love to swap it out. Is there / can
>>>>> there be a compile time option to use a different engine?
>>>>
>>>>
>>>> No (I assume you want different regex syntax, probably PCRE).
>>>>
>>>
>>> libpcre would be fine, yes. Or the library that Ruby uses - either way.
>>
>>
>>> Yeah, it looks like sed's syntax. If I'm used to writing things one way
>>> (say in code) and then hit '/' to do a similar thing inside my editor,
>>> switching mindset constantly makes me loose my thought (generally what
>>> happens) or make stupid errors like earlier in this thread.
>>
>>
>> I feel the same sometimes, as I code Perl in Vim on a daily
>> basis, but Vim's (old) regex engine/syntax actually allows useful
>> things which are impossible or hard inn Perl, not only the other
>> way around. And I can always filter through a perl oneliner if I
>> want to use perl's regex engine. Can't you do the same with Ruby?
>> Vim regexes come closer to Perl's if you use of \v and so that
>> ought to bring you closer to PCRE too unless the "PC" is now only
>> an historical leftover (I haven't looked at the specs in a long
>> time, but hey) The only thing I regularly miss in Vim regexes is
>> \Q...\E. \V...\v comes close, although you still have to escape
>> your backslashes under \V.
>>
>> So I guess I should file a feature request for support of \Q,
>> although someone probably has already...
>
> To have this a way to embed variable is needed in first place. Otherwise
> you would need to escape \E which can only be done with a more complex

Perl's \Q not only quotes interpolated variables,
but also any metacharacters, so that \Q[]\E is equivalent to \[\],
which is useful when searching for perl variables...

The way Perl's \Q does (not) interact with \\E is indeed annoying

> (compared to escape()) substitute() call or a new function. AFAIR embedding
> variables was indeed requested.

Some syntax for that, like \%{varname} could be added to Vim.

>
> The thing I constantly miss in vim RE engine is unicode and locales support.

Yeah, but I've kind of resigned to the lack of it, but it would be
nice to get rid of the shenanigans I use to make up, for sure!

BTW I'm on a UTF-8 locale, so I seldom need (other) locales.

>
>> /bpj
>>
>>
>> --
>> --
>> 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].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>

--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.


12