Interesting, I just read this in a book on vexillology. As well as your red, green, and yellow, black is also popular in both regions. This will be a shorter abridged version of what is in Tim Marshall's Worth Dying For: The Power and Politics of Flags which I highly recommend reading.
In Africa, it stems from the flag of Ethiopia, as it was the only uncolonised African country (Liberia is another matter not for this topic). That flag's coulours stem from the apparent colour of the rainbow after the Great Flood of Genesis. Marcus Garvey, leader of the US organisation UNIA, took inspiration from this to create the UNIA flag that contained red, green, and black, as he misthought the Ethiopian flag had black instead of yellow. Rastafarianism also helped combine the two separate 3 colour schemes together. Many African flags stem from these four 'colours of Africa'.
As for the Middle East, yellow has been replaced by white. The three colours were first brought together as the Arab Revolt flag during the First World War to unify the Arabs against the Ottomans. The white represents the Umayyad dynasty, responsible for expanding the caliphate from Portugal to Samarkand. Green represents the Fatimid dynasty but is also considered to be the colour of Islam as it was the Prophet's favourite colour. Black represents the colour of the Prophet's main banner and the headdress worn by pre-Islamic tribesmen in battle, while red is the colour of Sharif Hussein's tribe, included because he is the one who designed the Arab Revolt flag.
If you want to know what each country says the colours of their flag officially represent, the book has chapters dedicated to both regions.