-1

I'm trying to clean shortcodes from a dynamic html code.

Here is the ruby regex so far: /(?:\[\/?)[^\/\]]+\/?\]/

It works great with all codes that close like this:

[vc_column]...[/vc_column]

But not with:

[vc_video link='https://vimeo.com/abc' align='center']
# In this case there is no [/vc_video]

Here is a permalink to rubular: http://rubular.com/r/5et0W0Q73A with vc_video inside not matched.

Any idea? Thank you.

Yassine
  • 143
  • 1
  • 8
  • 2
    Hint: Your video shortcode is not matched __not__ because there's no closing `[/vc_video]`, but because of the slashes in the url. – Sergio Tulentsev Oct 06 '17 at 09:30
  • Hint: https://regex101.com is way better than http://rubular.com :) – Sergio Tulentsev Oct 06 '17 at 09:36
  • @SergioTulentsev Thank you but how to fix this so that it works ? – Yassine Oct 06 '17 at 09:36
  • "how to fix this" - modify your regex so that it allows slashes at any place within a tag. Maybe this will break some other usecases. ¯\\_(ツ)_/¯ I recommend unit-testing this extensively, so that you can instantly detect when you introduce a regression. – Sergio Tulentsev Oct 06 '17 at 09:39
  • Your issue is not clear at all. What is your input, and what is your desired output? Regex is just an object. It does not do anything unless you use it with some method. – sawa Oct 06 '17 at 09:46
  • @sawa My question is very clear; but thank you for your time. – Yassine Oct 06 '17 at 09:49

1 Answers1

1

Solution is this regex:

\[(.*?)\]
Sergio Tulentsev
  • 210,238
  • 40
  • 347
  • 343
Yassine
  • 143
  • 1
  • 8