0

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
3
  • If you allow any of your paths to contain commas (which is an allowed character under Windows), this is an impossible problem unless each path is separated in some other way. Commented Jan 21, 2010 at 13:45
  • None of the paths will ever contain commas. Commented Jan 21, 2010 at 16:10
  • How 'bout a combination of IndexOf('\"') and LastIndexOf('\"') and then Split(',') instead? I can quarantee this would be both easier to maintain and faster. Commented Jan 21, 2010 at 19:18

3 Answers 3

1

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)
Sign up to request clarification or add additional context in comments.

9 Comments

thanks, but how would that work with a dynamic flv and a dynamic jpg?
also, I tried the Telerik Converter but got a syntax error. Any chance you have some VB knowledge?
What do you mean by a dynamic flv and a dynamic jpg? You can put any string you want into the Split call.
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.
@SLaks: I think you're missing the closing quote in the input string.
|
0

Have you considered using the Split function?

string x  = "{video=\"my/video/file.flv,my/location.jpg\"}";
string xx = x.Split(',');

1 Comment

It needs to be a regex match because the "my/video/file.flv" and the "my/location.jpg" will always be changing.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.