[Project_owners] regex help

WC Leung lwchk2001 at yahoo.com.hk
Mon Apr 24 00:00:20 EDT 2006


You should run the re.exec multiple times, like below:

var s = "PROXY   mozilla.netscape.com:8081; SOCKS 
w3proxy.netscape.com:444;DIRECT"
var re = /\s*(\S+)\s+(\S+):(\d*)\s*[;]?\s*/g;

var a;
while (a = re.exec(s))
   alert(a.toSource());

Pls also notice the "g" modifier is a MUST. Otherwise the script will hang.

WC Leung


Eric H. Jung 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


More information about the Project_owners mailing list