Home > Mobile >  How to remove from a string questions asked with a clear pattern in R?
How to remove from a string questions asked with a clear pattern in R?

Time:08-26

Let's assume I have a text like the following one:

x = "\n\n\n\n\n\nTranscript of the questions asked and the answers given by Dr. Willem F. Duisenberg, President of the ECB and Christian Noyer, Vice-President of the ECB\n\n\n\nQuestion: Dr. Duisenberg, on structural reform, when you talk to economists about the euro's exchange rate weakness with the dollar, some of them don't point to anything to do with the currency per se but talk about the lack of structural reform, particularly in labour markets and particularly in Germany, for a factor which keeps the exchange rate down long term. What is your opinion on the matter and your opinion on the state of structural reforms, the amount of progress, or the lack thereof?\nDuisenberg. There has been some progress with structural reform. It is certainly not the case that nothing has been done in the past couple of years, but it is certainly not enough. And it has to be continued with force, we hope, and that is also everything that the governments are working towards, especially the Spanish presidency, ahead of the European summit in Barcelona this year. As far as the causes are concerned, the analysis you just gave was recently also given by Mr. Greenspan, who also ascribed the lack of movement in the exchange rate to the far lower degree of flexibility in the economy of Europe as compared with the United States and, as usual, I happen to agree with him.\nQuestion: Mr. President, you have said many times, and also very recently, that you are expecting an appreciation of the euro. Would you say that the changeover, or yesterday, is a turning-point for the currency?\nDuisenberg. I will not speculate further. I am here to fight speculation rather than to add to it. But certainly the movement of the past couple of days was, well, to say the least, gratifying to see. \nQuestion: Mr. Duisenberg, you have told us several times already that whenever there was an intervention by the ECB in the currency market, you would tell us. So, could you tell us something today on this issue?\nDuisenberg. I have also learnt never to talk again about intervention until after the event. So I won't do that today either.\nQuestion: A question to you, Mr. President, and to the Vice-President also if he maybe has something to add to the question. Do you expect a wider use of the euro as a reserve currency of central banks outside the euro zone as a denomination for bonds, especially corporate ones, or do you think it is possible that all will be paid in euro instead of dollars one day and, if so, when?\nDuisenberg. The last parts of the question will undoubtedly be answered by Mr. Noyer. The use of the euro as an international reserve currency is increasing, but very slowly. And it was expected to be very slow, but increasingly we are getting signals that countries, especially central banks of countries, are beginning to realise the possibilities they now have to diversify their reserve holdings. But it is not something we are aiming for, we will just let it happen. But it is happening, and the fact that, for example, in the recent experiences of the cash changeover, we have frontloaded to more than 20 non-euro area central banks sizeable sums, billions and billions worth of euro banknotes, is already an indication of this. The fact also that in the eastern hemisphere, where we are, more than 50 countries, in one way or the other, link their currency or align their currency to the euro is also a telling aspect of the phenomenon. But I don't want to ask Mr. Noyer to speculate about the \"when\", precisely if I assume he knows as much as I do."

As you can see, questions are asked with a clear pattern: \nQuestion: .....?\n. I would like to remove every question asked from the text. I have been playing with gsub but not very successfully so far. The outcome would be:

x = "\n\n\n\n\n\nTranscript of the questions asked and the answers given by Dr. Willem F. Duisenberg, President of the ECB and Christian Noyer, Vice-President of the ECB\n\n\nDuisenberg. There has been some progress with structural reform. It is certainly not the case that nothing has been done in the past couple of years, but it is certainly not enough. And it has to be continued with force, we hope, and that is also everything that the governments are working towards, especially the Spanish presidency, ahead of the European summit in Barcelona this year. As far as the causes are concerned, the analysis you just gave was recently also given by Mr. Greenspan, who also ascribed the lack of movement in the exchange rate to the far lower degree of flexibility in the economy of Europe as compared with the United States and, as usual, I happen to agree with him.Duisenberg. I will not speculate further. I am here to fight speculation rather than to add to it. But certainly the movement of the past couple of days was, well, to say the least, gratifying to see. Duisenberg. I have also learnt never to talk again about intervention until after the event. So I won't do that today either.Duisenberg. The last parts of the question will undoubtedly be answered by Mr. Noyer. The use of the euro as an international reserve currency is increasing, but very slowly. And it was expected to be very slow, but increasingly we are getting signals that countries, especially central banks of countries, are beginning to realise the possibilities they now have to diversify their reserve holdings. But it is not something we are aiming for, we will just let it happen. But it is happening, and the fact that, for example, in the recent experiences of the cash changeover, we have frontloaded to more than 20 non-euro area central banks sizeable sums, billions and billions worth of euro banknotes, is already an indication of this. The fact also that in the eastern hemisphere, where we are, more than 50 countries, in one way or the other, link their currency or align their currency to the euro is also a telling aspect of the phenomenon. But I don't want to ask Mr. Noyer to speculate about the \"when\", precisely if I assume he knows as much as I do."

Can anyone help me with this?

Thanks!

CodePudding user response:

You can do

gsub('\nQuestion:.*?\\?', '', x)

resulting in

cat(gsub('\nQuestion:.*?\\?', '', x))






Transcript of the questions asked and the answers given by Dr. Willem F. Duisenberg, President of the ECB and Christian Noyer, Vice-President of the ECB



Duisenberg. There has been some progress with structural reform. It is certainly not the case that nothing has been done in the past couple of years, but it is certainly not enough. And it has to be continued with force, we hope, and that is also everything that the governments are working towards, especially the Spanish presidency, ahead of the European summit in Barcelona this year. As far as the causes are concerned, the analysis you just gave was recently also given by Mr. Greenspan, who also ascribed the lack of movement in the exchange rate to the far lower degree of flexibility in the economy of Europe as compared with the United States and, as usual, I happen to agree with him.
Duisenberg. I will not speculate further. I am here to fight speculation rather than to add to it. But certainly the movement of the past couple of days was, well, to say the least, gratifying to see. 
Duisenberg. I have also learnt never to talk again about intervention until after the event. So I won't do that today either.
Duisenberg. The last parts of the question will undoubtedly be answered by Mr. Noyer. The use of the euro as an international reserve currency is increasing, but very slowly. And it was expected to be very slow, but increasingly we are getting signals that countries, especially central banks of countries, are beginning to realise the possibilities they now have to diversify their reserve holdings. But it is not something we are aiming for, we will just let it happen. But it is happening, and the fact that, for example, in the recent experiences of the cash changeover, we have frontloaded to more than 20 non-euro area central banks sizeable sums, billions and billions worth of euro banknotes, is already an indication of this. The fact also that in the eastern hemisphere, where we are, more than 50 countries, in one way or the other, link their currency or align their currency to the euro is also a telling aspect of the phenomenon. But I don't want to ask Mr. Noyer to speculate about the "when", precisely if I assume he knows as much as I do

CodePudding user response:

Another option using rm_between from qdapRegex:

x = "\n\n\n\n\n\nTranscript of the questions asked and the answers given by Dr. Willem F. Duisenberg, President of the ECB and Christian Noyer, Vice-President of the ECB\n\n\n\nQuestion: Dr. Duisenberg, on structural reform, when you talk to economists about the euro's exchange rate weakness with the dollar, some of them don't point to anything to do with the currency per se but talk about the lack of structural reform, particularly in labour markets and particularly in Germany, for a factor which keeps the exchange rate down long term. What is your opinion on the matter and your opinion on the state of structural reforms, the amount of progress, or the lack thereof?\nDuisenberg. There has been some progress with structural reform. It is certainly not the case that nothing has been done in the past couple of years, but it is certainly not enough. And it has to be continued with force, we hope, and that is also everything that the governments are working towards, especially the Spanish presidency, ahead of the European summit in Barcelona this year. As far as the causes are concerned, the analysis you just gave was recently also given by Mr. Greenspan, who also ascribed the lack of movement in the exchange rate to the far lower degree of flexibility in the economy of Europe as compared with the United States and, as usual, I happen to agree with him.\nQuestion: Mr. President, you have said many times, and also very recently, that you are expecting an appreciation of the euro. Would you say that the changeover, or yesterday, is a turning-point for the currency?\nDuisenberg. I will not speculate further. I am here to fight speculation rather than to add to it. But certainly the movement of the past couple of days was, well, to say the least, gratifying to see. \nQuestion: Mr. Duisenberg, you have told us several times already that whenever there was an intervention by the ECB in the currency market, you would tell us. So, could you tell us something today on this issue?\nDuisenberg. I have also learnt never to talk again about intervention until after the event. So I won't do that today either.\nQuestion: A question to you, Mr. President, and to the Vice-President also if he maybe has something to add to the question. Do you expect a wider use of the euro as a reserve currency of central banks outside the euro zone as a denomination for bonds, especially corporate ones, or do you think it is possible that all will be paid in euro instead of dollars one day and, if so, when?\nDuisenberg. The last parts of the question will undoubtedly be answered by Mr. Noyer. The use of the euro as an international reserve currency is increasing, but very slowly. And it was expected to be very slow, but increasingly we are getting signals that countries, especially central banks of countries, are beginning to realise the possibilities they now have to diversify their reserve holdings. But it is not something we are aiming for, we will just let it happen. But it is happening, and the fact that, for example, in the recent experiences of the cash changeover, we have frontloaded to more than 20 non-euro area central banks sizeable sums, billions and billions worth of euro banknotes, is already an indication of this. The fact also that in the eastern hemisphere, where we are, more than 50 countries, in one way or the other, link their currency or align their currency to the euro is also a telling aspect of the phenomenon. But I don't want to ask Mr. Noyer to speculate about the \"when\", precisely if I assume he knows as much as I do."
x
#> [1] "\n\n\n\n\n\nTranscript of the questions asked and the answers given by Dr. Willem F. Duisenberg, President of the ECB and Christian Noyer, Vice-President of the ECB\n\n\n\nQuestion: Dr. Duisenberg, on structural reform, when you talk to economists about the euro's exchange rate weakness with the dollar, some of them don't point to anything to do with the currency per se but talk about the lack of structural reform, particularly in labour markets and particularly in Germany, for a factor which keeps the exchange rate down long term. What is your opinion on the matter and your opinion on the state of structural reforms, the amount of progress, or the lack thereof?\nDuisenberg. There has been some progress with structural reform. It is certainly not the case that nothing has been done in the past couple of years, but it is certainly not enough. And it has to be continued with force, we hope, and that is also everything that the governments are working towards, especially the Spanish presidency, ahead of the European summit in Barcelona this year. As far as the causes are concerned, the analysis you just gave was recently also given by Mr. Greenspan, who also ascribed the lack of movement in the exchange rate to the far lower degree of flexibility in the economy of Europe as compared with the United States and, as usual, I happen to agree with him.\nQuestion: Mr. President, you have said many times, and also very recently, that you are expecting an appreciation of the euro. Would you say that the changeover, or yesterday, is a turning-point for the currency?\nDuisenberg. I will not speculate further. I am here to fight speculation rather than to add to it. But certainly the movement of the past couple of days was, well, to say the least, gratifying to see. \nQuestion: Mr. Duisenberg, you have told us several times already that whenever there was an intervention by the ECB in the currency market, you would tell us. So, could you tell us something today on this issue?\nDuisenberg. I have also learnt never to talk again about intervention until after the event. So I won't do that today either.\nQuestion: A question to you, Mr. President, and to the Vice-President also if he maybe has something to add to the question. Do you expect a wider use of the euro as a reserve currency of central banks outside the euro zone as a denomination for bonds, especially corporate ones, or do you think it is possible that all will be paid in euro instead of dollars one day and, if so, when?\nDuisenberg. The last parts of the question will undoubtedly be answered by Mr. Noyer. The use of the euro as an international reserve currency is increasing, but very slowly. And it was expected to be very slow, but increasingly we are getting signals that countries, especially central banks of countries, are beginning to realise the possibilities they now have to diversify their reserve holdings. But it is not something we are aiming for, we will just let it happen. But it is happening, and the fact that, for example, in the recent experiences of the cash changeover, we have frontloaded to more than 20 non-euro area central banks sizeable sums, billions and billions worth of euro banknotes, is already an indication of this. The fact also that in the eastern hemisphere, where we are, more than 50 countries, in one way or the other, link their currency or align their currency to the euro is also a telling aspect of the phenomenon. But I don't want to ask Mr. Noyer to speculate about the \"when\", precisely if I assume he knows as much as I do."
library(qdapRegex)
rm_between(x, "\nQuestion:", "?\n", extract = F)
#> [1] "Transcript of the questions asked and the answers given by Dr. Willem F. Duisenberg, President of the ECB and Christian Noyer, Vice-President of the ECB Duisenberg. There has been some progress with structural reform. It is certainly not the case that nothing has been done in the past couple of years, but it is certainly not enough. And it has to be continued with force, we hope, and that is also everything that the governments are working towards, especially the Spanish presidency, ahead of the European summit in Barcelona this year. As far as the causes are concerned, the analysis you just gave was recently also given by Mr. Greenspan, who also ascribed the lack of movement in the exchange rate to the far lower degree of flexibility in the economy of Europe as compared with the United States and, as usual, I happen to agree with him. Duisenberg. I will not speculate further. I am here to fight speculation rather than to add to it. But certainly the movement of the past couple of days was, well, to say the least, gratifying to see. Duisenberg. I have also learnt never to talk again about intervention until after the event. So I won't do that today either. Duisenberg. The last parts of the question will undoubtedly be answered by Mr. Noyer. The use of the euro as an international reserve currency is increasing, but very slowly. And it was expected to be very slow, but increasingly we are getting signals that countries, especially central banks of countries, are beginning to realise the possibilities they now have to diversify their reserve holdings. But it is not something we are aiming for, we will just let it happen. But it is happening, and the fact that, for example, in the recent experiences of the cash changeover, we have frontloaded to more than 20 non-euro area central banks sizeable sums, billions and billions worth of euro banknotes, is already an indication of this. The fact also that in the eastern hemisphere, where we are, more than 50 countries, in one way or the other, link their currency or align their currency to the euro is also a telling aspect of the phenomenon. But I don't want to ask Mr. Noyer to speculate about the \"when\", precisely if I assume he knows as much as I do."

Created on 2022-08-26 with reprex v2.0.2

  • Related