cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
%3CLINGO-SUB%20id%3D%22lingo-sub-518525%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%E5%88%86%E5%89%B2%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BB%A5%E6%8F%90%E5%8F%96%E6%95%B0%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518525%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%E4%BD%A0%E5%A5%BD%20%EF%BC%8C%3C%2FP%3E%3CP%3E%E6%88%91%E6%9C%89%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E5%AD%97%E7%AC%A6%E4%B8%B2%EF%BC%8C%E6%88%91%E6%83%B3%E6%8F%90%E5%8F%96%204%20%E4%B8%AA%E6%95%B0%E5%AD%97%E9%83%A8%E5%88%86%E3%80%82%E6%95%B0%E5%AD%97%E7%9A%84%E4%BD%8D%E7%BD%AE%E5%8F%AF%E8%83%BD%E4%BC%9A%E6%94%B9%E5%8F%98%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E8%AF%A5%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E7%A4%BA%E4%BE%8B%E5%8F%AF%E4%BB%A5%E6%98%AF%3C%2FP%3E%3CP%3E%E5%80%BC%3D%E2%80%9C%E4%BD%A0%E5%A5%BD0123%E7%A4%BA%E4%BE%8B%E2%80%9D%EF%BC%9B%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E6%88%91%E5%B7%B2%E7%BB%8F%E5%B0%9D%E8%AF%95%E8%BF%87%E8%BF%99%E4%B8%AA%EF%BC%8C%E4%BD%86%E5%8F%AA%E6%9C%89%E5%BD%93%E6%95%B0%E5%AD%97%E4%BD%8D%E4%BA%8E%E6%AD%A3%E7%A1%AE%E7%9A%84%E4%BD%8D%E7%BD%AE%E6%97%B6%E6%89%8D%E6%9C%89%E6%95%88%E3%80%82%3C%2FP%3E%3CP%3E%E5%80%BC%3D%E2%80%9C%E4%BD%A0%E5%A5%BD0123%E7%A4%BA%E4%BE%8B%E2%80%9D%EF%BC%9B%3C%2FP%3E%3CP%3E%E6%8F%90%E5%8F%96%3Dsubstr(%E5%80%BC%2C7%2C4)%3B%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%E7%94%B1%E4%BA%8E%E6%95%B0%E5%AD%97%E7%9A%84%E4%BD%8D%E7%BD%AE%E4%BC%9A%E6%94%B9%E5%8F%98%EF%BC%8C%E6%88%91%E8%AF%A5%E5%A6%82%E4%BD%95%E6%8F%90%E5%8F%96%E5%AE%83%EF%BC%9F%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-518525%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CLINGO-LABEL%3E%E9%AB%98%E7%BA%A7%E7%BB%9F%E8%AE%A1%E5%BB%BA%E6%A8%A1%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518567%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E6%8B%86%E5%88%86%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BB%A5%E6%8F%90%E5%8F%96%E6%95%B0%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518567%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%A5%BD%E7%9A%84%E8%B0%A2%E8%B0%A2%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F15446%22%20target%3D%22_blank%22%3E%40Aurora_TiffanyD%3C%2FA%3E%E5%92%8C%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F14366%22%20target%3D%22_blank%22%3E%40jthi%3C%2FA%3E%20%EF%BC%81%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518566%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E6%8B%86%E5%88%86%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BB%A5%E6%8F%90%E5%8F%96%E6%95%B0%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518566%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E8%BF%99%E5%8F%AF%E8%83%BD%E6%9B%B4%E5%A5%BD%EF%BC%8C%E5%9B%A0%E4%B8%BA%E6%82%A8%E4%B8%8D%E5%BF%85%E6%8A%A2%E7%AC%AC%E4%B8%80%E5%9C%BA%E6%AF%94%E8%B5%9B%E3%80%82%E8%B0%A2%E8%B0%A2%EF%BC%81%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518565%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E6%8B%86%E5%88%86%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BB%A5%E6%8F%90%E5%8F%96%E6%95%B0%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518565%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%8F%A6%E4%B8%80%E7%A7%8D%E9%80%89%E6%8B%A9%E6%98%AF%E4%BD%BF%E7%94%A8%20Regex%20%E8%80%8C%E4%B8%8D%E6%98%AF%20Regex%20Match%EF%BC%88%E8%BF%98%E6%9C%89%E6%9B%B4%E5%A4%9A%E9%80%89%E9%A1%B9%E5%8F%AF%E4%BB%A5%E5%A6%82%E4%BD%95%E5%AE%8C%E6%88%90%EF%BC%8C%E4%BD%86%E6%88%91%E8%AE%A4%E4%B8%BA%20Regex%20%E5%92%8C%20Regex%20Match%20%E6%98%AF%E6%9C%80%E7%AE%80%E5%8D%95%E7%9A%84%EF%BC%89%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0Astring%20%3D%20%22Hello%200123%20example%22%3B%0Afour_num%20%3D%20Regex(string%2C%20%22%5Cd%7B4%7D%22)%3B%26nbsp%3B%2F%2F0123%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%E7%9C%8B%3CA%20href%3D%22https%3A%2F%2Fregex101.com%2Fr%2F26hBdb%2F1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fregex101.com%2Fr%2F26hBdb%2F1%3C%2FA%3E%E5%A6%82%E6%9E%9C%E6%82%A8%E4%B8%8D%E7%86%9F%E6%82%89%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%8C%E8%AF%B7%E4%BA%86%E8%A7%A3%E5%AE%83%E7%9A%84%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518564%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E6%8B%86%E5%88%86%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BB%A5%E6%8F%90%E5%8F%96%E6%95%B0%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518564%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E8%BF%99%E5%B0%B1%E5%83%8F%E4%B8%80%E4%B8%AA%E9%AD%85%E5%8A%9B%E3%80%82%20%E5%A4%AA%E6%84%9F%E8%B0%A2%E4%BA%86%EF%BC%81%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518561%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E6%8B%86%E5%88%86%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BB%A5%E6%8F%90%E5%8F%96%E6%95%B0%E5%AD%97%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518561%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E4%BD%A0%E5%8F%AF%E4%BB%A5%E5%B0%9D%E8%AF%95%E8%BF%99%E6%A0%B7%E7%9A%84%E4%BA%8B%E6%83%85%EF%BC%9A%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0Astring%20%3D%20%22Hello%200123%20example%22%3B%0Amatches%20%3D%20Regex%20Match(%0A%20string%2C%0A%20%22%5B0-9%5D%7B4%7D%22%2C%0A)%3B%0A%2F%2F%20ASSUMES%20that%20you%20are%20interested%20only%20in%20the%20first%204-digit%20number%2C%20if%20there%20is%20more%20than%20one%0AextractedNumber%20%3D%20matches%5B1%5D%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%E8%BF%99%E5%B0%86%E8%BF%94%E5%9B%9E%E2%80%9C0123%E2%80%9D%E3%80%82%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%E8%AF%B7%E6%B3%A8%E6%84%8F%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%82%A8%E8%BE%93%E5%85%A5%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%98%AF%E2%80%9CHello%2001234%20example%E2%80%9D%EF%BC%8C%E5%AE%83%E4%BB%8D%E4%BC%9A%E8%BF%94%E5%9B%9E%E2%80%9C0123%E2%80%9D%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
B1234
Level III

Splitting a string to extract numbers

Hi , 

I have a string that is character and I want to extract a 4 number section. The position of the numbers may change

 

An example of the string may be

value ="Hello 0123 example";

 

I have tried this but only works if the numbers are in the correct position. 

value ="Hello 0123 example";

extract=substr(value,7, 4);

 

As the position of the number will change how can I extract this?

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Splitting a string to extract numbers

You could try something like this:

Names Default To Here( 1 );

string = "Hello 0123 example";
matches = Regex Match(
	string,
	"[0-9]{4}",
);
// ASSUMES that you are interested only in the first 4-digit number, if there is more than one
extractedNumber = matches[1];

This returns "0123".

 

Please note that it still returns "0123" if your input string is "Hello 01234 example".

View solution in original post

jthi
Super User

Re: Splitting a string to extract numbers

One other option is to use Regex instead of Regex Match (there are also more options how this could be done, but I think Regex and Regex Match are the easiest ones)

Names Default To Here(1);

string = "Hello 0123 example";
four_num = Regex(string, "\d{4}"); //0123

See https://regex101.com/r/26hBdb/1 for how regex this works if you are not familiar with it.

-Jarmo

View solution in original post

5 REPLIES 5

Re: Splitting a string to extract numbers

You could try something like this:

Names Default To Here( 1 );

string = "Hello 0123 example";
matches = Regex Match(
	string,
	"[0-9]{4}",
);
// ASSUMES that you are interested only in the first 4-digit number, if there is more than one
extractedNumber = matches[1];

This returns "0123".

 

Please note that it still returns "0123" if your input string is "Hello 01234 example".

B1234
Level III

Re: Splitting a string to extract numbers

This worked like a charm. Thank you so much!

jthi
Super User

Re: Splitting a string to extract numbers

One other option is to use Regex instead of Regex Match (there are also more options how this could be done, but I think Regex and Regex Match are the easiest ones)

Names Default To Here(1);

string = "Hello 0123 example";
four_num = Regex(string, "\d{4}"); //0123

See https://regex101.com/r/26hBdb/1 for how regex this works if you are not familiar with it.

-Jarmo

Re: Splitting a string to extract numbers

This is probably better because you don't have to grab the first match.  Thanks!

B1234
Level III

Re: Splitting a string to extract numbers

ok thank you @Aurora_TiffanyD and @jthi !