cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

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

Extracting a number from a text field

I have a column containing text notes entered by technicians. They enter the system usage hours, which I need to extract into it's own column. Fortunately, the data is pretty consistent, and so I have been able to pull the info out using Regex Match(), but selecting the last value is tripping me up.

Regex Match( :diagnosis, "(ys.+sage: ?)(\d{1,5})\n" );

How do I extract the System Usage hours from the text block effectively?

 

Sample text looks like this:

UDI# 123456789123456789123456789456123

Device received, missing cover.

Major Reason For Service: xxxxxxxxxx

System usage: 2372
System PM due in: 7627
xxx usage: 120
yyy usage: 208

 

2 REPLIES 2
jthi
Super User

Re: Extracting a number from a text field

If the data is consistent enough you could do this without regex by using Substr with Contains (and Length)

Names Default To Here(1);
text ="UDI# 123456789123456789123456789456123

    Device received, missing cover.

    Major Reason For Service: xxxxxxxxxx

    System usage: 2372
    System PM due in: 7627
    xxx usage: 120
    yyy usage: 208";
  
stringToSearch = "System usage: ";
sysUsage = num(Substr(text, Contains(text, stringToSearch) + length(stringToSearch), 4));
show(sysUsage);

Edit1: Or by using Words and Word:

Names Default To Here(1);
text ="
UDI# 123456789123456789123456789456123

Device received, missing cover.

Major Reason For Service: xxxxxxxxxx

System usage: 2372
System PM due in: 7627
xxx usage: 120
yyy usage: 208";

list_of_rows = Words(text, "\!N");
Show(list_of_rows);
sysUsage = Word(3, list_of_rows[4]);
Show(sysUsage);

Edit2: And finally regex with same text:

Names Default To Here(1);
text ="
UDI# 123456789123456789123456789456123

Device received, missing cover.

Major Reason For Service: xxxxxxxxxx

System usage: 2372
System PM due in: 7627
xxx usage: 120
yyy usage: 208";

//note "\2"
matchRegex = Regex(text, "(System usage: )(\d{1,5})", "\2");
Show(matchRegex);

//note index of number
matchList = Regex Match(text,"(System usage: )(\d{1,5})");
Show(matchList);
Show(matchList[3]);

 

-Jarmo
txnelson
Super User

Re: Extracting a number from a text field

Here is a solution that uses JSL functions to extract the System Usage

Num( Word( 1, Substr( :Diagnosis, Contains( :Diagnosis, "System usage:" ) + 14 ), "\!n" ) )

systemusage.PNG

I have attached the above data table

Jim

Recommended Articles