To match numbers preceded by #
use (?<=#)\d+
(positive lookbehind
for #
, then a non-empty sequence of digits).
To match numbers not preceded by #
use (?<!\d|#)\d+
(negative lookbehind).
This time however the “forbidden” preceding char is either a #
or a digit.
Of course, use both patterns with g
(global) option.
If you want to process all numbers is a single loop and within this
loop detect, whether the number has a preceding #
, you can use another
option, namely (#?)(\d+)
.
This pattern contains 2 groups:
- optional
#
and - a sequence of digits.
Then, processing each match, read the number from group 2 and check group 1,
whether it contains the #
.
0
solved Get only numbers after a certain character (#) with regex [closed]