I tried to replace the fourth occurrence of "_" in a string. For instance,
Enter
AAA_BBB_CCC_DD_D_EEE
Output
AAA_BBB_CCC_DDD_EEE
Can anyone suggest a solution?
You can use the backlink ....
gsub( "(_[^_]+_[^_]+_[^_]+)_" , "\\1" , x ) # [1] "AAA_BBB_CCC_DDD_EEE"
EDIT And thanks to @SonyGeorge below this can be further simplified:
gsub( "((_[^_]+){3})_" , "\\1" , x )
I donβt know which platform you are going to use.
pattern = (([^_]+_){3}[^_]+)_(.*) replacement = $1.$2 // concat 1 and 2
Source: https://habr.com/ru/post/1543552/More articles:Azure Bing Web Search Search with Query Search - azureDifference between ftp apache setDefaultimeout (), setSoTimeout () and setDataTimeout () - javaAngstrom installation on Beaglebone black - linuxDataContractJsonSerializerOperationFormatter not deserializing using JSON.NET - c #Removing duplicates from search results - elasticsearchERROR: query has no destination for result data - sqlProbability prediction for GBM using the carriage library - rHow can I define 2 classes in one var? - javascriptGBM classification with card - rHow to quickly delete lines in a file that contains items from a list in another file in BASH? - optimizationAll Articles