I want to extact all numbers from the string. I want to use the Lookahead and Lookbehind Zero-Length Assertions to do it (https://bedigit.com/blog/regex-how-t...cular-pattern/).
Code:
clear
input str64 x
"math:96;chinese:85; english:92; physical:90;"
"math:91;chinese:82; english:88; physical:98;"
"math:86;chinese:85; english:81; physical:90;"
"math:93;chinese:85; english:88; physical:90;"
"math:70;chinese:85; english:83; physical:91;"
"math:80;chinese:85; english:81; physical:92;"
end
gen grade1 = ustrregexs(1) if ustrregexm(x, "(?<=\:)([0-9]{2})")
list
+-----------------------------------------------------------+
| x grade1 |
|-----------------------------------------------------------|
1. | math:96;chinese:85; english:92; physical:90; 96 |
2. | math:91;chinese:82; english:88; physical:98; 91 |
3. | math:86;chinese:85; english:81; physical:90; 86 |
4. | math:93;chinese:85; english:88; physical:90; 93 |
5. | math:70;chinese:85; english:83; physical:91; 70 |
|-----------------------------------------------------------|
6. | math:80;chinese:85; english:81; physical:92; 80 |
+-----------------------------------------------------------+
Thanks very much!
Bests,
wanhai
0 Response to regex expression, extract the number from string
Post a Comment