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.李书颖"],","
1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: How is this regular expression replacement implemented

The original data rows contain fields that are arrays (author and authorID.) The stack option determines if those arrays make more rows.

unstacked keeps the multiple authors on one row:

Craige_Hales_0-1766991826913.png

vs stacked, which produces the 9 rows (the sampler won't always show all the values, but this time they all fit):

Craige_Hales_1-1766992032117.png

Unstacked can collapse the authorID like this (using expression to hold the authorID Col):

Craige_Hales_2-1766992518643.png

You can change the author field too, if it helps, but the comma separated list in the character field might be easier to use than an expression for the numeric field. Or you might prefer the authorID_N column names.

Above, I removed a bunch of columns (to focus on the author columns.) You can select multiple columns in the table view at the bottom and then click any selected Col in the top and change them all to "no column" to remove unwanted columns.

 

Craige

View solution in original post

10 REPLIES 10
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!

jthi
Super User

Re: How is this regular expression replacement implemented

You do it once manually to let JMP assist you in scripting like you always should do with graphs, platforms and table transforms. 

 

Create a .json file from your string

jthi_0-1766985795233.png

Use JMP's Open and locate the file and open it as Using Preview

jthi_1-1766985819563.png

Try different options in the wizard. This is the result after just using Wide guess

jthi_2-1766985849879.png

Export it to JMP if it looks fine. Check Source table script

jthi_3-1766985879513.png

This could be OK for you if the structure is already the same. If not, go to scripting index/jmp help and check if Open has any better options to use. Quickly looking it doesn't, look for JSON from Scripting Index. Come across JSON To Data Table which seems to have mention of Guess and "Wide"

jthi_4-1766986059961.png

Click Topic Help to get useful information about the argumentsJSON To Data Table(JSON string, (<Private(Boolean)>|<Invisible(Boolean)>), <Guess(Stack(Boolean)|"Ta... 

jthi_5-1766986102499.png

Remember that you used "Wide" Guess in the JSON Wizard.

Modify your script to use Guess with JSON To Data Table

View more...
Names Default To Here(1);

json = "\[[{"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"}]]\";

dt_json = JSON To Data Table(json, Guess(Stack(0), "Wide"));
-Jarmo
Craige_Hales
Super User

Re: How is this regular expression replacement implemented

The original data rows contain fields that are arrays (author and authorID.) The stack option determines if those arrays make more rows.

unstacked keeps the multiple authors on one row:

Craige_Hales_0-1766991826913.png

vs stacked, which produces the 9 rows (the sampler won't always show all the values, but this time they all fit):

Craige_Hales_1-1766992032117.png

Unstacked can collapse the authorID like this (using expression to hold the authorID Col):

Craige_Hales_2-1766992518643.png

You can change the author field too, if it helps, but the comma separated list in the character field might be easier to use than an expression for the numeric field. Or you might prefer the authorID_N column names.

Above, I removed a bunch of columns (to focus on the author columns.) You can select multiple columns in the table view at the bottom and then click any selected Col in the top and change them all to "no column" to remove unwanted columns.

 

Craige

Recommended Articles