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%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20%EB%B6%84%ED%95%A0%ED%95%98%EC%97%AC%20%EC%88%AB%EC%9E%90%20%EC%B6%94%EC%B6%9C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518525%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%EC%95%88%EB%85%95%20%2C%3C%2FP%3E%3CP%3E%EB%AC%B8%EC%9E%90%EC%9D%B8%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%B4%20%EC%9E%88%EA%B3%A0%204%EC%9E%90%EB%A6%AC%20%EC%88%AB%EC%9E%90%20%EC%84%B9%EC%85%98%EC%9D%84%20%EC%B6%94%EC%B6%9C%ED%95%98%EA%B3%A0%20%EC%8B%B6%EC%8A%B5%EB%8B%88%EB%8B%A4.%20%EC%88%AB%EC%9E%90%EC%9D%98%20%EC%9C%84%EC%B9%98%EB%8A%94%20%EB%B0%94%EB%80%94%20%EC%88%98%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%98%20%EC%98%88%EB%8A%94%20%EB%8B%A4%EC%9D%8C%EA%B3%BC%20%EA%B0%99%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3CP%3Evalue%20%3D%22%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94%200123%20%EC%98%88%EC%8B%9C%22%3B%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%EB%82%98%EB%8A%94%20%EC%9D%B4%EA%B2%83%EC%9D%84%20%EC%8B%9C%EB%8F%84%ED%96%88%EC%A7%80%EB%A7%8C%20%EC%88%AB%EC%9E%90%EA%B0%80%20%EC%98%AC%EB%B0%94%EB%A5%B8%20%EC%9C%84%EC%B9%98%EC%97%90%20%EC%9E%88%EB%8A%94%20%EA%B2%BD%EC%9A%B0%EC%97%90%EB%A7%8C%20%EC%9E%91%EB%8F%99%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3CP%3Evalue%20%3D%22%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94%200123%20%EC%98%88%EC%8B%9C%22%3B%3C%2FP%3E%3CP%3Eextract%3Dsubstr(%EA%B0%92%2C7%2C4)%3B%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%EC%88%AB%EC%9E%90%EC%9D%98%20%EC%9C%84%EC%B9%98%EA%B0%80%20%EB%B0%94%EB%80%8C%EB%8A%94%EB%8D%B0%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%EC%B6%94%EC%B6%9C%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%82%98%EC%9A%94%3F%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%EA%B3%A0%EA%B8%89%20%ED%86%B5%EA%B3%84%20%EB%AA%A8%EB%8D%B8%EB%A7%81%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%3ERe%3A%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20%EB%B6%84%ED%95%A0%ED%95%98%EC%97%AC%20%EC%88%AB%EC%9E%90%20%EC%B6%94%EC%B6%9C%ED%95%98%EA%B8%B0%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518567%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%EB%84%A4%20%EA%B0%90%EC%82%AC%ED%95%A9%EB%8B%88%EB%8B%A4%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F15446%22%20target%3D%22_blank%22%3E%20%40Aurora_TiffanyD%3C%2FA%3E%20%EA%B7%B8%EB%A6%AC%EA%B3%A0%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F14366%22%20target%3D%22_blank%22%3E%20%40jthi%3C%2FA%3E%20!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518566%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20%EB%B6%84%ED%95%A0%ED%95%98%EC%97%AC%20%EC%88%AB%EC%9E%90%20%EC%B6%94%EC%B6%9C%ED%95%98%EA%B8%B0%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518566%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%EC%B2%AB%20%EA%B2%BD%EA%B8%B0%EB%A5%BC%20%EC%9E%A1%EC%9D%84%20%ED%95%84%EC%9A%94%EA%B0%80%20%EC%97%86%EA%B8%B0%20%EB%95%8C%EB%AC%B8%EC%97%90%20%EC%9D%B4%EA%B2%83%EC%9D%80%20%EC%95%84%EB%A7%88%EB%8F%84%20%EB%8D%94%20%EB%82%98%EC%9D%84%20%EA%B2%83%EC%9E%85%EB%8B%88%EB%8B%A4.%EA%B0%90%EC%82%AC%ED%95%B4%EC%9A%94!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518565%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20%EB%B6%84%ED%95%A0%ED%95%98%EC%97%AC%20%EC%88%AB%EC%9E%90%20%EC%B6%94%EC%B6%9C%ED%95%98%EA%B8%B0%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518565%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%EB%8B%A4%EB%A5%B8%20%EC%98%B5%EC%85%98%EC%9D%80%20Regex%20Match%20%EB%8C%80%EC%8B%A0%20Regex%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%8A%94%20%EA%B2%83%EC%9E%85%EB%8B%88%EB%8B%A4(%EC%9D%B4%20%EC%9E%91%EC%97%85%EC%9D%84%20%EC%88%98%ED%96%89%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%B4%20%EB%8D%94%20%EC%9E%88%EC%A7%80%EB%A7%8C%20Regex%20%EB%B0%8F%20Regex%20Match%EA%B0%80%20%EA%B0%80%EC%9E%A5%20%EC%89%AC%EC%9A%B4%20%EC%98%B5%EC%85%98%EC%9D%B4%EB%9D%BC%EA%B3%A0%20%EC%83%9D%EA%B0%81%ED%95%A9%EB%8B%88%EB%8B%A4).%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%EB%B3%B4%EB%8B%A4%3CA%20href%3D%22https%3A%2F%2Fregex101.com%2Fr%2F26hBdb%2F1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%20https%3A%2F%2Fregex101.com%2Fr%2F26hBdb%2F1%3C%2FA%3E%20%EC%9D%B5%EC%88%99%ED%95%98%EC%A7%80%20%EC%95%8A%EC%9D%80%20%EA%B2%BD%EC%9A%B0%20%EC%A0%95%EA%B7%9C%EC%8B%9D%EC%9D%B4%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%EC%9E%91%EB%8F%99%ED%95%98%EB%8A%94%EC%A7%80%20%ED%99%95%EC%9D%B8%ED%95%98%EC%8B%AD%EC%8B%9C%EC%98%A4.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518564%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20%EB%B6%84%ED%95%A0%ED%95%98%EC%97%AC%20%EC%88%AB%EC%9E%90%20%EC%B6%94%EC%B6%9C%ED%95%98%EA%B8%B0%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518564%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%EC%9D%B4%EA%B2%83%EC%9D%80%20%EB%A7%A4%EB%A0%A5%EC%B2%98%EB%9F%BC%20%EC%9E%91%EB%8F%99%ED%96%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%20%EB%A7%A4%EC%9A%B0%20%EA%B0%90%EC%82%AC%ED%95%A9%EB%8B%88%EB%8B%A4!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-518561%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20%EB%B6%84%ED%95%A0%ED%95%98%EC%97%AC%20%EC%88%AB%EC%9E%90%20%EC%B6%94%EC%B6%9C%ED%95%98%EA%B8%B0%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-518561%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%EB%8B%A4%EC%9D%8C%EA%B3%BC%20%EA%B0%99%EC%9D%B4%20%EC%8B%9C%EB%8F%84%ED%95%B4%20%EB%B3%BC%20%EC%88%98%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%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%EC%9D%B4%EA%B2%83%EC%9D%80%20%220123%22%EC%9D%84%20%EB%B0%98%ED%99%98%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%EC%9E%85%EB%A0%A5%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%B4%20%22Hello%2001234%20example%22%EC%9D%B8%20%EA%B2%BD%EC%9A%B0%20%EC%97%AC%EC%A0%84%ED%9E%88%20%220123%22%EC%9D%84%20%EB%B0%98%ED%99%98%ED%95%A9%EB%8B%88%EB%8B%A4.%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 !