Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

hash and args

Last post 07-30-2008, 11:00 AM by trashman. 2 replies.
Sort Posts: Previous Next
  •  07-21-2008, 1:21 PM 44417

    hash and args

    greetings,

     

     in javascript, i'm trying to pull out pieces of a url via regex. my url looks like this:

     

    http://domain.com/index.html#hash=http://domain.com/index.php?arg=val&arg2=val2&meta=val&meta2=val

     

    I want to be able to extract everything after hash= up until meta=. but i want it to go to meta= if it finds it, meta2 if it doesn't find meta, and until the end of the line if it finds neither of the meta args.

     

    i've tried this, to no avail: string.match( /hash=(.+)(?:&meta=|&meta2=)*/ )

     

    what am i doing wrong? many thanks!

    tr

  •  07-21-2008, 7:24 PM 44424 in reply to 44417

    Re: hash and args

    This seems to work:

    hash=(((?!&meta2?=).)+)

    (you will need to add in the delimiters etc. yourself). The matching text is in match group #1.

    However, this will stop at the first instance of "meta" or "meta2" and I'm not clear from your example and requirements whether "meta" will always come before "meta2". If "meta2" can come before "meta", then what should happen?

    By the way, you pattern will match the literal "hash=", then grab everything to the end of the text/line (depending on the 'single line' option setting) and then check for whether the next characters are "&meta=" or "&meta2=" which they won't be (you are at the end of the text/line). However, because of the '*' quantifier, having 0 matches is OK so the whole pattern will complete. Is that the "wrong" behaviour you were experiencing?

    Susan 

  •  07-30-2008, 11:00 AM 44756 in reply to 44424

    Re: hash and args

    This works perfectly, thank you kindly Susan!
View as RSS news feed in XML