cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-351251%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%BE%9E%E6%96%87%E6%9C%AC%E5%AD%97%E6%AE%B5%E4%B8%AD%E6%8F%90%E5%8F%96%E6%95%B8%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-351251%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%88%91%E6%9C%89%E4%B8%80%E5%88%97%E5%8C%85%E5%90%AB%E6%8A%80%E8%A1%93%E4%BA%BA%E5%93%A1%E8%BC%B8%E5%85%A5%E7%9A%84%E6%96%87%E6%9C%AC%E8%A8%BB%E9%87%8B%E3%80%82%20%E4%BB%96%E5%80%91%E8%BC%B8%E5%85%A5%E7%B3%BB%E7%B5%B1%E4%BD%BF%E7%94%A8%E6%99%82%E9%96%93%EF%BC%8C%E6%88%91%E9%9C%80%E8%A6%81%E5%B0%87%E5%85%B6%E6%8F%90%E5%8F%96%E5%88%B0%E5%AE%83%E8%87%AA%E5%B7%B1%E7%9A%84%E5%88%97%E4%B8%AD%E3%80%82%20%E5%B9%B8%E9%81%8B%E7%9A%84%E6%98%AF%EF%BC%8C%E6%95%B8%E6%93%9A%E9%9D%9E%E5%B8%B8%E4%B8%80%E8%87%B4%EF%BC%8C%E6%89%80%E4%BB%A5%E6%88%91%E8%83%BD%E5%A4%A0%E4%BD%BF%E7%94%A8%20Regex%20Match()%20%E6%8F%90%E5%8F%96%E4%BF%A1%E6%81%AF%EF%BC%8C%E4%BD%86%E9%81%B8%E6%93%87%E6%9C%80%E5%BE%8C%E4%B8%80%E5%80%8B%E5%80%BC%E8%AE%93%E6%88%91%E6%84%9F%E5%88%B0%E5%9B%B0%E6%83%91%E3%80%82%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ERegex%20Match(%20%3Adiagnosis%2C%20%22(ys.%2Bsage%3A%20%3F)(%5Cd%7B1%2C5%7D)%5Cn%22%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%E5%A6%82%E4%BD%95%E6%9C%89%E6%95%88%E5%9C%B0%E5%BE%9E%E6%96%87%E6%9C%AC%E5%A1%8A%E4%B8%AD%E6%8F%90%E5%8F%96%E7%B3%BB%E7%B5%B1%E4%BD%BF%E7%94%A8%E6%99%82%E9%96%93%EF%BC%9F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E7%A4%BA%E4%BE%8B%E6%96%87%E6%9C%AC%E5%A6%82%E4%B8%8B%E6%89%80%E7%A4%BA%EF%BC%9A%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3EUDI%23%20123456789123456789123456789456123%3C%2FP%3E%3CP%3E%E8%A8%AD%E5%82%99%E6%94%B6%E5%88%B0%EF%BC%8C%E7%BC%BA%E5%B0%91%E8%93%8B%E5%AD%90%E3%80%82%3C%2FP%3E%3CP%3E%E6%9C%8D%E5%8B%99%E7%9A%84%E4%B8%BB%E8%A6%81%E5%8E%9F%E5%9B%A0%EF%BC%9Axxxxxxxxxx%3C%2FP%3E%3CP%3E%E7%B3%BB%E7%B5%B1%E4%BD%BF%E7%94%A8%EF%BC%9A2372%3CBR%20%2F%3E%E7%B3%BB%E7%B5%B1%20PM%20%E5%88%B0%E6%9C%9F%E6%99%82%E9%96%93%EF%BC%9A7627%3CBR%20%2F%3E%20xxx%20%E7%94%A8%E6%B3%95%EF%BC%9A120%3CBR%20%2F%3E%E5%B9%B4%E5%B9%B4%E4%BD%BF%E7%94%A8%E9%87%8F%EF%BC%9A208%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-351251%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3E%E5%88%86%E6%9E%90%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3E%E6%95%B8%E6%93%9A%E8%A1%A8%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-351273%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%BE%9E%E6%96%87%E6%9C%AC%E5%AD%97%E6%AE%B5%E4%B8%AD%E6%8F%90%E5%8F%96%E6%95%B8%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-351273%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E9%80%99%E6%98%AF%E4%B8%80%E5%80%8B%E4%BD%BF%E7%94%A8%20JSL%20%E5%87%BD%E6%95%B8%E6%8F%90%E5%8F%96%E7%B3%BB%E7%B5%B1%E4%BD%BF%E7%94%A8%E6%83%85%E6%B3%81%E7%9A%84%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%A1%88%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENum(%20Word(%201%2C%20Substr(%20%3ADiagnosis%2C%20Contains(%20%3ADiagnosis%2C%20%22System%20usage%3A%22%20)%20%2B%2014%20)%2C%20%22%5C!n%22%20)%20)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22systemusage.PNG%22%20style%3D%22width%3A%20566px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22systemusage.PNG%22%20style%3D%22width%3A%20566px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22systemusage.PNG%22%20style%3D%22width%3A%20566px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F29604iC83F6E598279830C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22systemusage.PNG%22%20alt%3D%22systemusage.PNG%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%E6%88%91%E9%99%84%E4%B8%8A%E4%BA%86%E4%B8%8A%E9%9D%A2%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-351271%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%BE%9E%E6%96%87%E6%9C%AC%E5%AD%97%E6%AE%B5%E4%B8%AD%E6%8F%90%E5%8F%96%E6%95%B8%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-351271%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%A6%82%E6%9E%9C%E6%95%B8%E6%93%9A%E8%B6%B3%E5%A4%A0%E4%B8%80%E8%87%B4%EF%BC%8C%E6%82%A8%E5%8F%AF%E4%BB%A5%E5%9C%A8%E6%B2%92%E6%9C%89%E6%AD%A3%E5%89%87%E8%A1%A8%E9%81%94%E5%BC%8F%E7%9A%84%E6%83%85%E6%B3%81%E4%B8%8B%E9%80%9A%E9%81%8E%E4%BD%BF%E7%94%A8%20Substr%20with%20Contains%EF%BC%88%E5%92%8C%20Length%EF%BC%89%E4%BE%86%E5%81%9A%E5%88%B0%E9%80%99%E4%B8%80%E9%BB%9E%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0Atext%20%3D%22UDI%23%20123456789123456789123456789456123%0A%0A%20%20%20%20Device%20received%2C%20missing%20cover.%0A%0A%20%20%20%20Major%20Reason%20For%20Service%3A%20xxxxxxxxxx%0A%0A%20%20%20%20System%20usage%3A%202372%0A%20%20%20%20System%20PM%20due%20in%3A%207627%0A%20%20%20%20xxx%20usage%3A%20120%0A%20%20%20%20yyy%20usage%3A%20208%22%3B%0A%20%20%0AstringToSearch%20%3D%20%22System%20usage%3A%20%22%3B%0AsysUsage%20%3D%20num(Substr(text%2C%20Contains(text%2C%20stringToSearch)%20%2B%20length(stringToSearch)%2C%204))%3B%0Ashow(sysUsage)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EEdit1%EF%BC%9A%E6%88%96%E8%80%85%E9%80%9A%E9%81%8E%E4%BD%BF%E7%94%A8%20Words%20%E5%92%8C%20Word%EF%BC%9A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0Atext%20%3D%22%0AUDI%23%20123456789123456789123456789456123%0A%0ADevice%20received%2C%20missing%20cover.%0A%0AMajor%20Reason%20For%20Service%3A%20xxxxxxxxxx%0A%0ASystem%20usage%3A%202372%0ASystem%20PM%20due%20in%3A%207627%0Axxx%20usage%3A%20120%0Ayyy%20usage%3A%20208%22%3B%0A%0Alist_of_rows%20%3D%20Words(text%2C%20%22%5C!N%22)%3B%0AShow(list_of_rows)%3B%0AsysUsage%20%3D%20Word(3%2C%20list_of_rows%5B4%5D)%3B%0AShow(sysUsage)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%E7%B7%A8%E8%BC%AF2%EF%BC%9A%3CCODE%20class%3D%22%20language-jsl%22%3E%3C%2FCODE%3E%E6%9C%80%E5%BE%8C%E4%BD%BF%E7%94%A8%E7%9B%B8%E5%90%8C%E6%96%87%E6%9C%AC%E7%9A%84%E6%AD%A3%E5%89%87%E8%A1%A8%E9%81%94%E5%BC%8F%EF%BC%9A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0Atext%20%3D%22%0AUDI%23%20123456789123456789123456789456123%0A%0ADevice%20received%2C%20missing%20cover.%0A%0AMajor%20Reason%20For%20Service%3A%20xxxxxxxxxx%0A%0ASystem%20usage%3A%202372%0ASystem%20PM%20due%20in%3A%207627%0Axxx%20usage%3A%20120%0Ayyy%20usage%3A%20208%22%3B%0A%0A%2F%2Fnote%20%22%5C2%22%0AmatchRegex%20%3D%20Regex(text%2C%20%22(System%20usage%3A%20)(%5Cd%7B1%2C5%7D)%22%2C%20%22%5C2%22)%3B%0AShow(matchRegex)%3B%0A%0A%2F%2Fnote%20index%20of%20number%0AmatchList%20%3D%20Regex%20Match(text%2C%22(System%20usage%3A%20)(%5Cd%7B1%2C5%7D)%22)%3B%0AShow(matchList)%3B%0AShow(matchList%5B3%5D)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
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