I have some large batches of data that I am matching with a regex and the /g option to repeat. Here is a simplified example of the data:
I am using the following regular expression for this example. The number of 'int's can change on me.int A Number of Flaps: 6 IP Address: 2.2.2.2 int B Number of Flaps: 8 IP Address 5.5.5.5 unpredictable data int C Number of Flaps: 9 IP Address 9.9.9.9
The problem is thus: the regex matches 'A' and 'C', not 'B', because of the unpredictable data that has sown up in 'B'. This is of course correct, but my desired behaviour is for the regex to fail because of the fact that 'B' didn't match. In other words, I want the next iteration of the regex to have to pick up where the last one left off, so that /g is not allowed to skip over sections of text it doesn't match. Is this possible? I know but I could write a full regex and not use /g, but the number of 'int's does change. I desire the best of both worlds.^(?:int)\s+(\w+)\s*?\n (?:\s*Number\sof\sFlaps:\s(\d+)\s*?\n)? (?:\s*IP\sAddress:?\s([\d\.]+)\s*?\n)? (?=^int|\Z)
Is there any way I can have my cake and eat it too?
Thanks in advance,
Scott
In reply to Making regex /g match continuously by scottb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |