in reply to Multiple regex catches on a line
You need the /g in this example even if you don't expect the same regex to appear on the same line multiple times. The advantage to this example is that it significantly(well,depending on the regex) cuts down on the amount of backtracking that is neccessary by the NFA machine. You could also take that out of the while loop, and do this:while(/(regex1)/gi || /(regex2)/gi || /(regex3)/gi)
while(<file>) { (/(regex1)/i || /(regex2)/i || /(regex3)/i) && f($1); }
The advantage to this situation is that, if needed, you can call specific functions(or do specific actions) on a per regex level. E.g., :
while(<file>) { #put a while around the regexes if there is multiple #regexes per line; aslo add a /g ( (/(regex1)/i && doSomethingForRegex1($1)) || (/(regex2)/i && doSomethingForRegex2($1)) || (/(regex3)/i && doSomethingForRegex3($1)) ) && still_do_a_general_func_if_needed($1); }
|
|---|