I seem to be having some mixed results with this one: var tStr : String = '-path:c:\test path\temp -param spaced string -x' var patt : RegExp = new RegExp( '(?<=[-{1,2}|/])(?P<name>[a-zA-Z0-9]*)(?::|=)*(?P<value>[\w|.|?|=|&|+| |:|/|\\]*)(?=[ |"]|$)' , 'g'); var result : Object = patt.exec(tStr );
As it currently stands - it's not picking up P<value> properly. it seems to be working in Grants RegExp tool. But am having issues picking up the groups in my code. This is my first attempt with RegExp, I guess it's not the easiest start. Maybe it would be better to write a parser for this one, but am curious to know if it can be done with AS3 RegExp. Cheers Karim On 13 Mar 2011, at 09:27, Karim Beyrouti wrote: > This is great - thanks for explaining, helps a lot. > > the original expression I posted works this tool : http://gskinner.com/RegExr > I would love to know what magic Grant is using to get it working in his > RegExp utility. > > > Thank you Anthony. > > > On 11 Mar 2011, at 23:42, Anthony Pace wrote: > >> Hi Karim and Ktu, >> >> Below is an explanation of what appears to be going on in the given pattern: >> >> (?:\s*) >> is a greedy non-capturing group of whitespace >> >> (?<=[-|/]) >> is looking behind the next section of the expression, (?<name>\w*), >> for, what is in this case, a character set; as well, it does so >> without including it in the result. In this case the character >> set could also be written without the |, resulting in [-/] >> >> (?<name>\w*) >> is looking for name>\w*, before the next expression [:|=] >> you may have wanted (?P<name>\w*) >> >> [:|=] >> is a character set : or =, but again does not need the |, >> and could be [:=] or something like (?::|=) >> >> ("((?<value>.*?)(?<!\\)")|(?<value>[\w]*)) >> is what I think you may have wanted to be an alternation, >> and in another language it would have worked; however, not in AS3. >> >> Apparently in AS3 in order to distinguish the syntax from a >> lookbehind ?< you need to use the syntax ?P<desiredGroupName> >> when defining a named group; as well, it is due to the fact that, >> as far as I know, in AS3 you cannot use names of the same group >> even a logical OR alternation. >> >> >> On 3/11/2011 2:37 PM, Ktu wrote: >>> I just plugged it into RegExr<http://www.regexr.com> and I can't make sense >>> of it. >>> >>> Try using that tool to build it. It really helps >>> >>> >>> On Fri, Mar 11, 2011 at 5:56 AM, Karim Beyrouti<ka...@kurst.co.uk> wrote: >>> >>>> Hello lovely list...I am trying to run a RegExp pattern on a String, and am >>>> not too sure why it's not working, and am not too sure why. >>>> Here is the code: >>>> >>>> var tStr : String = '/a:"value" -big="this" -test:123 >>>> -test2=th_3' >>>> var r : RegExp = new RegExp( >>>> '(?:\s*)(?<=[-|/])(?<name>\w*)[:|=]("((?<value>.*?)(?<!\\)")|(?<value>[\w]*))'); >>>> var result : Object = r.exec( str ); >>>> >>>> result returns null... Maybe you can shed some light on what i am doing >>>> wrong here? >>>> >>>> Thanks... >>>> >>>> >>>> Karim >>>> >>>> _______________________________________________ >>>> Flashcoders mailing list >>>> Flashcoders@chattyfig.figleaf.com >>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >>>> >>> >>> >> >> _______________________________________________ >> Flashcoders mailing list >> Flashcoders@chattyfig.figleaf.com >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders