cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Due to the recently reported Microsoft outage, users may be temporarily unable to access My JMP or experience a delay receiving their verification codes. If you have previously installed JMP on your computer, this outage should not impact your ability to access the software. My JMP services will be restored as soon as Microsoft resolves this issue.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

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

Extracting text from a column of strings

Hello,

I am a bit of a novice when it comes to scripting in JMP, and I am trying to write a script that would be able to extract specific numbers from a string and create new columns for each one. Each number would always follow the characters 'DX' or 'DY' For example:

D113U_NTCH_CM_MEAS_CD_SEM_{2UM_X6_NTCH_CM_IMAGE}_DX7DY11SDX11SDY15_2024-12-06_18-57-42.jpg

I would want to extract and create these columns:

SethTruex_0-1734372111786.png

Of course, I would like to repeat this process over an entire column of data. I'd appreciate any advice. Thanks!



4 REPLIES 4
jthi
Super User

Re: Extracting text from a column of strings

Do you know beforehand all the possible patterns (DX, DY, ....)? Is it always located in the same place (after }_ and before date)?

-Jarmo
BHarris
Level VII

Re: Extracting text from a column of strings

If I had a column full of those filenames, I would do a Cols -> Recode, top-left Red Triangle -> "Replace String", and then enter "S?D[XY](\d+)" and replace with "%\1%" with "Use regular expressions" turned on.  Then you can split the column (Cols -> Utilities -> Text to Columns...") and enter "%", which will give you 6 new columns, with the prefix, DX, DY, SDX, SDY, and suffix, e.g.:

 

Column 1 2Column 1 3Column 1 4Column 1 5Column 1 6Column 1 7
D113U_NTCH_CM_MEAS_CD_SEM_{2UM_X6_NTCH_CM_IMAGE}_7111115 _2024-12-06_18-57-42.jpg

 

Then you can rename the columns to DX, DY, etc.

 

If your real data is more complicated this process might need to be a bit more complicated as well.

hogi
Level XIII

Re: Extracting text from a column of strings

Nice : )
maybe start with 

 

word(8, filename,"_")

such that it works as well for lot DX11A.

txnelson
Super User

Re: Extracting text from a column of strings

Here is an alternative approach.  

Given the data table

txnelson_0-1735902155727.png

The below script will directly create

txnelson_1-1735902223229.png

Names Default To Here( 1 );

// Create and example data table
dt = New Table( "Example",
	Add Rows( 1 ),
	New Column( "File",
		Character,
		"Nominal",
		Set Values(
			{
			"D113U_NTCH_CM_MEAS_CD_SEM_{2UM_X6_NTCH_CM_IMAGE}_DX7DY11SDX11SDY15_2024-12-06_18-57-42.jpg"
			}
		)
	)
);

// Add the new columns to the data table
dt << New Column( "DX" );
dt << New Column( "DY" );
dt << New Column( "SDX" );
dt << New Column( "SDY" );

For Each Row(
	// Separate the section of the File name into just the DX,DY,SDX,SDY part
	string = Word( 1, Substr( :file, Contains( :file, "_DX" ) + 1 ), "_" );
	// Change the string into a assignment statements
	Substitute Into( string, "SDX", ";:SD_X=", "SDY", ";:SD_Y=", "DX", ";:D_X=", "DY", ";:D_Y=", "_", "" );
	string = Substr( string, 2 ) || ";";
	// Execute the assignment statements
	Eval( Parse( string ) );
);
Jim

Recommended Articles