syntax highlighting with regular expressions

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

syntax highlighting with regular expressions

Mark Volkmann-2
I'm trying to use "syntax region" with start=regex and end=regex, but having difficulty.
I want the region to match what follows the start regex and precedes the end regex.
For example, say I want to match whatever follows "foo" or "bar" and precedes "baz" or "qux".
So in these two examples, the word "test" should be highlighted:

  footestbaz
  bartestqux

Can someone show me an example that is similar to this?

--
R. Mark Volkmann
Object Computing, Inc.

--
--
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/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: syntax highlighting with regular expressions

Benjamin Fritz
On Saturday, July 5, 2014 5:26:15 PM UTC-5, Mark Volkmann wrote:

> I'm trying to use "syntax region" with start=regex and end=regex, but having difficulty.
> I want the region to match what follows the start regex and precedes the end regex.
> For example, say I want to match whatever follows "foo" or "bar" and precedes "baz" or "qux".
>
> So in these two examples, the word "test" should be highlighted:
>
>
>   footestbaz
>   bartestqux
>
>
> Can someone show me an example that is similar to this?

Why is it important that foo and baz don't get matched? Do you really need them not part of the match, or is it sufficient if they are matched but not highlighted? Or, highlighted differently from "test"?

--
--
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/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: syntax highlighting with regular expressions

Ben Klein
In reply to this post by Mark Volkmann-2
On Jul 5, 2014, at 5:24 PM, Mark Volkmann <[hidden email]> wrote:

> I'm trying to use "syntax region" with start=regex and end=regex, but having difficulty.
> I want the region to match what follows the start regex and precedes the end regex.
> For example, say I want to match whatever follows "foo" or "bar" and precedes "baz" or "qux".
> So in these two examples, the word "test" should be highlighted:
>
>   footestbaz
>   bartestqux
>
> Can someone show me an example that is similar to this?

I just threw this together in terminal Vim. Hopefully it’s some help. What I think may be key is that you need to set the `matchgroup`, which is the group the `start` and `end` patterns belong to.

**************************************************

syntax region testGroup matchgroup=endsGroup
      \ start=/foo/ end=/baz/

highlight testGroup ctermfg=lightblue

finish

fooyo this is text baz

**************************************************

“yo this is text” is highlighted in blue when I source the script.

Ben

--
b

Sent from my iPhone

--
--
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/d/optout.
BPJ
Reply | Threaded
Open this post in threaded view
|

Re: syntax highlighting with regular expressions

BPJ
In reply to this post by Benjamin Fritz


Den 6 jul 2014 01:03 skrev "Ben Fritz" <[hidden email]>:
>
> On Saturday, July 5, 2014 5:26:15 PM UTC-5, Mark Volkmann wrote:
> > I'm trying to use "syntax region" with start=regex and end=regex, but having difficulty.
> > I want the region to match what follows the start regex and precedes the end regex.
> > For example, say I want to match whatever follows "foo" or "bar" and precedes "baz" or "qux".
> >
> > So in these two examples, the word "test" should be highlighted:
> >
> >
> >   footestbaz
> >   bartestqux
> >
> >
> > Can someone show me an example that is similar to this?
>
> Why is it important that foo and baz don't get matched? Do you really need them not part of the match, or is it sufficient if they are matched but not highlighted? Or, highlighted differently from "test"?

Just out of curiosity (I'm in a vim-less environment ATM) would start='\%(foo\)\@<=' end='\%(bar\)\@=' work? Would it be undesirable even if it does work?

--
--
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/d/optout.