Perl regular expression in script not working as intended

Help with writing and running scripts

Re: Perl regular expression in script not working as intended

Postby pietzcker » Thu Oct 01, 2009 9:52 am

I think you want

Code: Select all
/(?<==)\w+(?=;|,)/

as your JavaScript regex object, so the line should be

Code: Select all
var findResult = selectedText.match(/(?<==)\w+(?=;|,)/);
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: Perl regular expression in script not working as intended

Postby wchu01 » Thu Oct 01, 2009 10:13 am

I have replaced with the following statement however it does not seems to work.

Code: Select all
var findResult = selectedText.match(/(?<==)\w+(?=;|,)/);


I apologies for not providing the text which I am working on earlier. I am trying to use the regex to extract those strings between the start marker of "=" and end marker of either "," or ";".

Code: Select all
C133   C                   1=UNNAMED_1_CON18_I1_A,
                              2=EARTH;
C133   C                   1=EARTH,
                              2=UNNAMED_1_CER_I28_A;
C177   C                   1=UNNAMED_2_CON18_I6_A,
                              2=EARTH;
U13   ACT138            1=UNNAMED_2_87C54C_I42,
                              2=UNNAMED_2_87C54C_I43,
                              3=UNNAMED_2_87C54C_I44,
                              4=_GND,
                              5=_GND,
                              6=UNNAMED_2_ACT138_I84,
                              8=_GND,
                              9=UNNAMED_1_DIGBLK_I47,
                              12=UNNAMED_1_DIGBLK_I46,
                              16=5V_VCC;
wchu01
Newbie
 
Posts: 3
Joined: Tue Sep 22, 2009 8:19 am

Re: Perl regular expression in script not working as intended

Postby pietzcker » Fri Oct 02, 2009 5:53 am

Oops. Big mistake on my part.

JavaScript does not support lookbehind; I forgot about that entirely.

So your alternative is to use

var findResult = selectedText.match(/=(\w+)(?=;|,)/);

and use findResult[1] as your match. I don't know JavaScript, you'd probably have to feed the selection to it line by line, or you will only get the first match.
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: Perl regular expression in script not working as intended

Postby wchu01 » Fri Oct 02, 2009 6:27 am

I understand that Javascript does not support lookbehind however the Perl Regex Engine within allows entry of Perl Expression that do lookbehind.
wchu01
Newbie
 
Posts: 3
Joined: Tue Sep 22, 2009 8:19 am

Re: Perl regular expression in script not working as intended

Postby Mofi » Fri Oct 02, 2009 7:50 am

The JavaScript core contains a regular expression object using the same syntax as the Perl regular expression engine. But the JavaScript core does not contain the entire, full featured perl regular expression engine. Don't mix that. The Javascript regular expression object using Perl syntax is not the Perl regular expression engine.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Previous

Return to Scripts