Reputation: 13
I am trying to extract the following string RL2.OPT.TEST.01
from this one a lot of text...[RL2.OPT.TEST.01]<some more text
. Basically there can be anything before the RL2.
but it always begins with RL2.
, and always finish by either ]
, <
, or a space.
I tried with the following regex: m/RL2\..*[\s<\]]+?$/g
but even if it finds a match for the string -- [RL2.OPT.TEST.01]
, it does not work for -- [RL2.OPT.TEST.01] some more text
.
I need an array of all the resultings matches in the large string I have. I think I should also mention that this string has a lot of newline characters, but never in the middle of the strings I am trying to extract.
Any clue about what is wrong with my regex?
Upvotes: 1
Views: 136
Reputation: 174706
Use a negated character class and remove the end of the line anchor $
m/RL2\.[^\s<\]]*/g
[^\s<\]]*
Negated character class which matches any character but not of space or <
or ]
zero or more times.
Upvotes: 3