[Project_owners] regex help

Didier Ernotte didier at ernotte.com
Tue Apr 18 20:11:27 EDT 2006


I have tried this

javascript:alert("PROXY w3proxy.netscape.com:8080; SOCKS
moofarm.com:1234".match(/\s*(\S+)\s+(\S+)\:(\d*)\s*[;]?\s*/))

and this give me your three expected results. I've just removed the 'g'
in the regexp. Otherwise, regexp always try to maximize the length of
any matched pattern. If you want to minizize it , juste the ? char.

Didier

--- "Eric H. Jung" <grimholtz at yahoo.com> wrote:

> Hi,
> 
> I'm trying to write a regex which parses 3 pieces of data multiple
> times. For example:
> 
> PROXY w3proxy.netscape.com:8080
> or
> PROXY mozilla.netscape.com:8081;PROXY w3proxy.netscape.com:8080
> or
>  PROXY   mozilla.netscape.com:8081; SOCKS
> w3proxy.netscape.com:444;DIRECT
> 
> The following works but only keeps the last match set:
> 
>   var re = /\s*(\S+)\s+(\S+):(\d*)\s*[;]?\s*/g;
> 
> In other words:
> 
>   var a = re.exec("PROXY w3proxy.netscape.com:8080; SOCKS
> moofarm.com:1234");
>   a[1] = "SOCKS";
>   a[2] = "moofarm.com";
>   a[3] = "1234";
> 
> but I also want:
> 
>   a[x] = "PROXY ";
>   a[y] = "w3proxy.netscape.com";
>   a[z] = "8080";
> 
> 
> Any advice is greatly appreciated.
> 
> Thank you,
> Eric Jung
> 
> Use Your PC To Find a Cure for
>
Cancerhttp://members.ud.com/services/teams/team.htm?id=68C9E079-8285-495F-8598-D73352CC7075And
> Join Team Lulu
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 



More information about the Project_owners mailing list