which looks for a literal octothorpe # character, then captures () 1 or more digits \d+ which follow it.
The // surrounding the regular expression simply delimit the regular expression in Groovy, and the =~ says that we should look for matches to that regular expression within text. The result is assigned to mc.
So mc[0] contains the first match, which is a list of two elements: the entire matched expression #12, and the first capturing group 12.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
text = 'Some 42 number #12 more'
def mc = (text =~ /#(\d+)/)
println mc[0] // [#12, 12]
println mc[0][0] // #12
println mc[0][1] // 12
and what about this??
The only regular expression here is
which looks for a literal octothorpe
#
character, then captures()
1 or more digits\d+
which follow it.The
//
surrounding the regular expression simply delimit the regular expression in Groovy, and the=~
says that we should look for matches to that regular expression withintext
. The result is assigned tomc
.So
mc[0]
contains the first match, which is a list of two elements: the entire matched expression#12
, and the first capturing group12
.