cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
lala
Level IX

How is this regular expression replacement implemented

The regular expressions of EmEditor

","(?=[^\[\]]*\])

to

&

How to modify JSL

",":["11000278031.胡剑","11000259239.胡慧","11000426432.叶子","11000445039.张大为","11000469637.詹浏洋","11000480631.李书颖"],","

to

",":["11000278031.胡剑&11000259239.胡慧&11000426432.叶子&11000445039.张大为&11000469637.詹浏洋&11000480631.李书颖"],","
7 REPLIES 7
lala
Level IX

回复: How is this regular expression replacement implemented

txt="\!",\!":[\!"11000278031.胡剑\!",\!"11000259239.胡慧\!",\!"11000426432.叶子\!",\!"11000445039.张大为\!",\!"11000469637.詹浏洋\!",\!"11000480631.李书颖\!"],\!",\!"";

tx="";tx = Regex(txt, "\[","(?=[^\[\]]*\])]\", "&");

Thanks Experts!

jthi
Super User

Re: How is this regular expression replacement implemented

 

Maybe something like this?

ames Default To Here(1);

str = "\[",":["11000278031.胡剑","11000259239.胡慧","11000426432.叶子","11000445039.张大为","11000469637.詹浏洋","11000480631.李书颖"],","]\";

res = Regex(str, "\[","(?=[^\[\]]*\])]\", "&", GLOBALREPLACE);
Write(res);

 

 

-Jarmo
Craige_Hales
Super User

Re: How is this regular expression replacement implemented

It is a truly obtuse pattern. I was so sure it wouldn't work I didn't even try it. So, why does it work?

The goal appears to be to replace the quote-comma-quote sequences, but only inside the [ square brackets ]. Somehow the positive look-ahead does that. 

(?=[^\[\]]*\])

means "look ahead for zero or more characters that are not square brackets, followed by a close square bracket."

So the quote-comma-quote before the [ can't match because the regex can't locate the trailing ] without being stopped by the [.

And the final quote-comma-quote after the ] can't match because there is not another ].

and the quote-comma-quote in the middle ... work.

Cool, I guess. But actually a fair amount of work for the regex engine; the positive look ahead is scanning to the end of the string over and over. I would not leave this for a future maintainer to figure out without some comments, and I'd probably do it more like this:

source = "\[
	",":["11000278031.胡剑","11000259239.胡慧","11000426432.叶子","11000445039.张大为","11000469637.詹浏洋","11000480631.李书颖"],","
]\";
Write( source );

findthis = "\!",\!""; // ","
replacewith = "&";

// goal: replace findthis  
//       with replacethis
//       but only inside the [ ... ] square brackets.

If( 0 < Contains( source, "[" ) < Contains( source, "]" ), "ok", Throw( "something wrong here" ));
parts = Words( source, "[]" );
If( N Items( parts ) == 3, "ok", Throw( "this needs more thought" ));
Substitute Into( parts[2], findthis, replacewith );
result = parts[1] || "[" || parts[2] || "]" || parts[3];

Write( result );

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_asse...

Craige
lala
Level IX

Re: How is this regular expression replacement implemented

Thank Craige!
Actually, I just want to know how this JSON can be turned into a perfect table

tx="\[[{"title":"AA,AA","BName":"AA","BCode":"605366","orgCode":"82004416","orgName":"AA","orgSName":"AA","publishDate":"2025-12-28 00:00:00.","infoCode":"AP202512281809952250","column":"002004006001","predictNextTwoYearB":"","predictNextTwoYearPe":"","predictNextYearB":"","predictNextYearPe":"","predictThisYearB":"","predictThisYearPe":"","predictLastYearB":"","predictLastYearPe":"","actualLastTwoYearB":"","actualLastYearB":"","industryCode":"","industryName":"","emIndustryCode":"","indvInduCode":"538","indvInduName":"AA","emBCode":"","emBValue":"","emBName":"","lastEmBCode":"","lastEmBValue":"","lastEmBName":"","BChange":"","reportType":2,"author":["11506051.AA"],"indvIsNew":"001","researcher":"AA","newListingDate":"2020-08-12 00:00:00.","newPurchaseDate":"2020-07-31 00:00:00.0","newIssueB":9.98,"newPeIssueA":22.78,"indvAimBT":"","indvAimBL":"","attachType":"0","attachSize":383,"attachPages":3,"encodeUrl":"6XT6d6nxZNcP9JXS1dtw9ivwowNnxWgBjsEKvrMIHoo=","sBName":"","sBCode":"","B":"SHANGHAI","authorID":["11506051"],"count":1,"orgType":"white"},{"title":"AAI,AA","BName":"AA","BCode":"688800","orgCode":"80036717","orgName":"AA","orgSName":"AA","publishDate":"2025-12-28 00:00:00.","infoCode":"AP202512281809913359","column":"002004001003","predictNextTwoYearB":"2.67","predictNextTwoYearPe":"32.97","predictNextYearB":"2.08","predictNextYearPe":"42.24","predictThisYearB":"1.46","predictThisYearPe":"60.44","predictLastYearB":"","predictLastYearPe":"","actualLastTwoYearB":"","actualLastYearB":"","industryCode":"","industryName":"","emIndustryCode":"","indvInduCode":"459","indvInduName":"AA","emBCode":"007","emBValue":"3","emBName":"AA","lastEmBCode":"007","lastEmBValue":"3","lastEmBName":"AA","BChange":3,"reportType":2,"author":["11392732.AA","11524834.AA"],"indvIsNew":"001","researcher":"AA,AA","newListingDate":"2021-07-22 00:00:00.","newPurchaseDate":"2021-07-12 00:00:00.0","newIssueB":15.02,"newPeIssueA":24.49,"indvAimBT":"","indvAimBL":"","attachType":"0","attachSize":764,"attachPages":5,"encodeUrl":"6XT6d6nxZNcP9JXS1dtw9snalC40a3QwRrj9tML8YAw=","sBName":"AA","sBCode":"0301","B":"SHANGHAI","authorID":["11392732","11524834"],"count":1,"orgType":"white"},{"title":"AA,AA","BName":"AA","BCode":"601038","orgCode":"80064","orgName":"AA","orgSName":"AA","publishDate":"2025-12-28 00:00:00.","infoCode":"AP202512281809893801","column":"002004002003","predictNextTwoYearB":"0.9","predictNextTwoYearPe":"15.7600","predictNextYearB":"0.8100","predictNextYearPe":"17.4900","predictThisYearB":"0.7900","predictThisYearPe":"17.9200","predictLastYearB":"","predictLastYearPe":"","actualLastTwoYearB":"","actualLastYearB":"","industryCode":"","industryName":"","emIndustryCode":"","indvInduCode":"910","indvInduName":"AA","emBCode":"007","emBValue":"3","emBName":"AA","lastEmBCode":"007","lastEmBValue":"3","lastEmBName":"AA","BChange":3,"reportType":2,"author":["11379333.AA"],"indvIsNew":"001","researcher":"AA","newListingDate":"2012-08-08 00:00:00.","newPurchaseDate":"2012-07-27 00:00:00.0","newIssueB":5.4,"newPeIssueA":14.44,"indvAimBT":"","indvAimBL":"","attachType":"0","attachSize":321,"attachPages":4,"encodeUrl":"6XT6d6nxZNcP9JXS1dtw9vuL66I7rHatL9vNIud7cP0=","sBName":"AA","sBCode":"0101","B":"SHANGHAI","authorID":["11379333"],"count":1,"orgType":"white"},{"title":"AA:AA,AA","BName":"AA","BCode":"002488","orgCode":"80162","orgName":"AA","orgSName":"AA","publishDate":"2025-12-25 00:00:00.","infoCode":"AP202512251807934364","column":"002004001003","predictNextTwoYearB":"1.0100","predictNextTwoYearPe":"8.4","predictNextYearB":"0.3300","predictNextYearPe":"25.4","predictThisYearB":"0.0600","predictThisYearPe":"131.8","predictLastYearB":"","predictLastYearPe":"","actualLastTwoYearB":"","actualLastYearB":"","industryCode":"","industryName":"","emIndustryCode":"","indvInduCode":"481","indvInduName":"AA","emBCode":"007","emBValue":"3","emBName":"AA","lastEmBCode":"","lastEmBValue":"","lastEmBName":"","BChange":2,"reportType":2,"author":["11250834.AA","11245529.AA","11442637.AA"],"indvIsNew":"001","researcher":"AA,AA,AA","newListingDate":"2010-10-21 00:00:00.","newPurchaseDate":"2010-10-11 00:00:00.0","newIssueB":22,"newPeIssueA":73.33,"indvAimBT":"","indvAimBL":"","attachType":"0","attachSize":2285,"attachPages":19,"encodeUrl":"MKF7cC+MZ9vDOQWsqD7ZgmRE9eUeYHJK9njuGLTcICI=","sBName":"AA(1)","sBCode":"0201","B":"SHENZHEN","authorID":["11250834","11245529","11442637"],"count":1,"orgType":"white"},{"title":"BDAA,AA","BName":"AA","BCode":"688621","orgCode":"80064","orgName":"AA","orgSName":"AA","publishDate":"2025-12-25 00:00:00.","infoCode":"AP202512251807725254","column":"002004006003","predictNextTwoYearB":"2.4600","predictNextTwoYearPe":"28.0","predictNextYearB":"2.2600","predictNextYearPe":"30.5400","predictThisYearB":"1.8","predictThisYearPe":"38.3300","predictLastYearB":"","predictLastYearPe":"","actualLastTwoYearB":"","actualLastYearB":"","industryCode":"","industryName":"","emIndustryCode":"","indvInduCode":"727","indvInduName":"AA","emBCode":"007","emBValue":"3","emBName":"AA","lastEmBCode":"007","lastEmBValue":"3","lastEmBName":"AA","BChange":3,"reportType":2,"author":["11296231.AA","11486715.AA"],"indvIsNew":"001","researcher":"AA,AA","newListingDate":"2021-06-21 00:00:00.","newPurchaseDate":"2021-06-09 00:00:00.0","newIssueB":26.89,"newPeIssueA":29.72,"indvAimBT":"","indvAimBL":"","attachType":"0","attachSize":315,"attachPages":4,"encodeUrl":"MKF7cC+MZ9vDOQWsqD7ZgvFJHAi4XRobbkVOxAB2GK4=","sBName":"AA","sBCode":"0101","B":"SHANGHAI","authorID":["11296231","11486715"],"count":1,"orgType":"white"}]]\";
 d1 =jsontodatatable(tx);

This will increase the number of lines

lala
Level IX

Re: How is this regular expression replacement implemented

Four rows have been added

That's why I came up with this stupid idea
Thanks Experts!2025-12-28_21-31-08.png

 

jthi
Super User

Re: How is this regular expression replacement implemented

JMP does offer JSON Import Wizard.

jthi_0-1766938981954.png

Is there a specific reason to avoid using that first? When you figure out which options to use that you can try to transform them to JSON To Data Table as it does offer you with some parameters such as Guess() or JSON Settings()

jthi_1-1766939211753.png

 

-Jarmo
lala
Level IX

Re: How is this regular expression replacement implemented

It can only be operated manually once

Thanks Experts!

Recommended Articles