grepx.ls


on grepx(xName, ptrn)
  
  xNameStr = ""
  repeat with i = 1 to (the xtras).count
    if ((xtra i).name starts xName) then put (xtra i).name & RETURN after xNameStr
  end repeat
  
  case (xNameStr.line.count) of
      
    (2): -- Good! Matched exactly one xtra name so use that. (Length is 2 because we appended a return.)
      ifStr = (xtra xNameStr.line[1]).interface()
      ifLst = []
      
      repeat while ifStr.length
        add ifLst, ifStr.line[1]
        delete ifStr.line[1]
      end repeat
      
      rslt = PRegEx_Grep(ifLst, ptrn, "gi") -- Search globally ignoring case.
      repeat while rslt.count
        put rslt[1] &RETURN after ifStr
        deleteAt rslt, 1
      end repeat
      
    (1): -- Couldn't find any xtras whose names begin with xName.
      ifStr = "Error: xtra not found" &RETURN &xName &RETURN
      
    otherwise -- Found more than one xtra name match so display what we found.
      ifStr = "Ambiguous xtra reference:" &RETURN &xNameStr
      
  end case
  
  put ifStr -- Display results in the message window.
  return ifStr -- And return as a string.
  
end

-- Check here for examples and a miaw tool version.