Replace numbers with dots
I am trying to replace some identification numbers on my system with a clickable number to open the corresponding entry. The problem is that they are sometimes in this format: 123.456.789. When I use my regex I can replace them and it works great. The problem is when I also have IP addresses where the regex is also used: 123. [123.123.123] ([] indicates where it matches).
How can I prevent this behavior?
I've tried something like this: /^(?!\.)([0-9]{3}\.[0-9]{3}\.[0-9]{3})(?!\.)/
I am working on "notes" in the ticket system. When the note contains only ID or IP, the regex works. When it contains more text, for example:
Affected IDs:
641.298.855 (this, lead)
213.794.868
948.895.285
Then it doesn't fit my IDs anymore. Could you please help me on this issue and explain what I am doing wrong?
source to share
You do not need to use a negative lookahead at the beginning, nor do you need to include a modifier g
, the modifier will suffice for this case m
, because it ^
matches the beginning of the line and the next pattern will match a line that only exists at the beginning, so there will be no global match (i.e. i.e. two or more matches in one line).
/^([0-9]{3}\.[0-9]{3}\.[0-9]{3})(?!\.)/m
For better performance, you no longer need to use a capture group.
/^[0-9]{3}\.[0-9]{3}\.[0-9]{3}(?!\.)/m
source to share