matching the last part of a url

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

matching the last part of a url

ericmsmith
I am not managing to crack this for a syntax highlight rile.

http|www.foo.bar/baz/baz     -> I want to match baz
http|www.foo.bar/baz/baz/    -> I want to match baz/
http|www.foo.bar/baz/baz/biz -> I want to match biz

Thanks for any solution.

Eric

--
--
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: matching the last part of a url

Tim Chase
On 2014-05-23 16:10, Eric Smith wrote:
> http|www.foo.bar/baz/baz     -> I want to match baz
> http|www.foo.bar/baz/baz/    -> I want to match baz/
> http|www.foo.bar/baz/baz/biz -> I want to match biz

Your "http|" is a little odd (I'd normally expect "https\=://", but if
that's actually what you have, you should be able to do something like

  \(http|\S*\/\)\@<=\w\+\/\=\S\@!

It's a little sloppy, as it assumes that the results you want to find
match "\w\+" while other characters could legitimately be there.
But that should give you the foundation for improving it.

It roughly translates to

 \(
  http|\S*\/
  \)\@>=   assert that the stuff preceding this is contextually a URL
 \w\+      the pattern we actually want
 \/\=      optionally a trailing slash
 \S\@!     assert that a non-whitespace doesn't follow the slash

-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

---
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: matching the last part of a url -> and in a syntax file

ericmsmith

Tim Chase wrote on Fri-23-May 14  6:32PM
>   \(http|\S*\/\)\@<=\w\+\/\=\S\@!

Thanks Tim, this works perfectly when tested with matchstr(),
however I need ti in a syntax file and there it appears to be a
noop. I tried;
syn match last_url '\(http\S*\/\)\@<=\w\+\/\=\S\@!'

Any ideas?

--
Eric Smith

--
--
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: matching the last part of a url -> and in a syntax file

Charles Campbell
Eric Smith wrote:
> Tim Chase wrote on Fri-23-May 14  6:32PM
>>    \(http|\S*\/\)\@<=\w\+\/\=\S\@!
> Thanks Tim, this works perfectly when tested with matchstr(),
> however I need ti in a syntax file and there it appears to be a
> noop. I tried;
> syn match last_url '\(http\S*\/\)\@<=\w\+\/\=\S\@!'
>
> Any ideas?
>
It should "work perfectly" as is in a syntax file, too.  I suspect that
you have some syntax priority issues going on.

* later syntax takes priority over earlier syntax:
   syn clear
   syn match One    'abc'
   syn match Two    'abc'

   hi link One    Function
   hi link Two Identifier

use this with a file containing only "abc".  Result: abc is highlighted
using #2 (Identifier).  Swap syn-matches One and Two and abc will be
highlighted using #1.

* regions have their own syntax highlighting, and may contain other
syntax recognition.
* nextgroup elevates priority of such syntax

Anyway, its involved.  So, may I suggest trying my plugin

   http://www.drchip.org/astronaut/vim/index.html#HILINKS

with its  :HLT!  command, move the cursor over the url: you'll be told
what highlighting groups are in use with the text under the cursor.

Regards,
Chip Campbell

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