tags:

views:

127

answers:

3

Does anyone know how to write a Regex.Split in order to convert

{video="my/video/file.flv,my/location.jpg"}

into

  1. my/video/file.flv
  2. my/location.jpg
+1  A: 

Like this:

new Regex(@"[{="",}]").Split(@"{video=""my/video/file.flv,my/location.jpg}").Where(s => s.Length > 0)

EDIT: In VB:

Dim regex As New Regex("[{="",}]")
Dim myStr = "{video=""my/video/file.flv,my/location.jpg}"

Dim results = regex.Split(myStr).Where(Function(s) s.Length > 0)
SLaks
thanks, but how would that work with a dynamic flv and a dynamic jpg?
rockinthesixstring
also, I tried the Telerik Converter but got a syntax error. Any chance you have some VB knowledge?
rockinthesixstring
What do you mean by a dynamic flv and a dynamic jpg? You can put any string you want into the `Split` call.
SLaks
it's going in a content management system. So basically they will put in {video="new/other/video.flv,a/different/image.jpg"}. What I want to do is replace the entire string with a JWPlayer oject that will play the video they tell it to.
rockinthesixstring
@SLaks: I think you're missing the closing quote in the input string.
Jon Seigel
...and this also returns the token "video" in the returned string array.
Jon Seigel
I can see how this would work if I hardcode the flv file path and the jpg file path, however I don't see how I would do it when the flv file path and jpg file path are changing.
rockinthesixstring
@Jon: I answered this before he edited the question. @Rock: You can use any string you want.
SLaks
I'm getting an error above. "Where is not a member of System.Array"
rockinthesixstring
A: 

Have you considered using the Split function?

string x  = "{video=\"my/video/file.flv,my/location.jpg\"}";
string xx = x.Split(',');
Johannes
It needs to be a regex match because the "my/video/file.flv" and the "my/location.jpg" will always be changing.
rockinthesixstring
A: 

This work around seems to have done the trick for me. Thoughts?

    Dim str As String = "this is exciting {video=""my/exciting/video.flv,my/refreshing/image.jpg""} this is refreshing"
    Dim regFind As String = "(?'text'\{video=""(.*)\""})"
    Dim matcher As Match = Regex.Match(str, regFind)

    Dim Matched As String() = (matcher.Groups("text").Value).Split(",")

    Dim video As String = Matched(0).Replace("{video=""", "")
    Dim jpg As String = Matched(1).Replace("""}", "")

    Response.Write(video)
    Response.Write("<br />")
    Response.Write(jpg)
rockinthesixstring