How to write regular expressions
-
wrote on 14 Jul 2022, 08:43 last edited by
Hi
I want to separate only the numbers in brackets [test10] [test25] [test30].
I tried. I wrote the regular expression below to extract the contents.
regex("(?<=\[)[^]]*(?=\])")result : test10, test25, test30 (remove parentheses)
But it couldn't separate alphabets and numbers.
I want to write a regular expression that can extract only the numbers in parentheses.
And I want to put that number in a list.
list.append(10)
list.append(25)
list.append(30) -
Hi
I want to separate only the numbers in brackets [test10] [test25] [test30].
I tried. I wrote the regular expression below to extract the contents.
regex("(?<=\[)[^]]*(?=\])")result : test10, test25, test30 (remove parentheses)
But it couldn't separate alphabets and numbers.
I want to write a regular expression that can extract only the numbers in parentheses.
And I want to put that number in a list.
list.append(10)
list.append(25)
list.append(30)wrote on 14 Jul 2022, 08:51 last edited by@LISP
Assuming your input strings are always <letters><digits> you might replace the[^]]*
with something like([A-Za-z]*)\\d*
to capture the letter parts.
A site like https://regex101.com/ is useful to go play till you get what you want.
1/2