#regex help

1 messages · Page 1 of 1 (latest)

tired condor
#

i need to split the string whenever i encounter a number and its separator eg 1) or 2) so i have this Arrays.stream(list.split("\D")).toList() how can i include the ) so it will split at both the digit and the closing bracket

cerulean acornBOT
#

<@&987246399047479336> please have a look, thanks.

fast galleon
#

use this as the regex:

\\d\\)
tired condor
#

thank you!! i give that a try

fast galleon
#

though you might need to update it

#
\\d+\\)
#

so it will match 10) as well, if you have multiple digits

tired condor
#

thank you that worked well!!

#

seriously thank you so musch it decreased my code by like 10 fold

fast galleon
#

you might be interested what that regex matches in the first place

#

so \d matches any digit

#

+ after the \d means that this will match any digit one or more times

#

\) matches the literal ) character, you need to escape it because the character has a meaning in regex

tired condor
#

ahh thank you, we didnt cover a lot in regex and i just found //D for digits.

#

U are literally my hero man

fast galleon
#

well \D isnt for digits

#

\d is for digits

tired condor
#

no wonder my code was going bonkers

fast galleon
#

you need to select java on the left side

tired condor
#

ah found it

#

thanks man 😭

#

if only college was as useful