Replacing word between commas not included in a list of words



  • Hello everyone,

    below the text I’d wish to get help with.

    https://url.com,"text - text",27305664219,10300104,https://images.url.com/products/jacket-original-piumino-smanicato-grigio-colorblock/20870943-1-asphalt?$XXL$,"Gilet di Brand Bello indossare una giacca nuova! Modello a blocchi di colore Collo a imbuto Chiusura con zip Etichetta con logo Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e Cappotti > Gilet",38.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-originals-piumino-smanicato-grigio-colorblock%2F20870943-1-asphalt%3F%24XXL%24&feedId=36675&k=40c130faec57ad6220fdad81baad41e935cc3845,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-originals-piumino-smanicato-grigio-colorblock/prd/20870943?browseCountry=IT&browseCurrency=EUR,,,EUR38.99,36675,"jack & jones",Grigio,,23527,,,,,"38.99 €","0.00 €",,,
    
    

    I’m wondering whether it is possible to replace any word, between the 22nd and the 23rd comma, different from these list of words

    • bianco
    • nero
    • rosso
    • giallo
    • blu
    • verde
    • arancione
    • grigio
    • viola
    • marrone
    • mimetico
    • beige
    • bordeaux

    into the word “altri”.

    Any help is much appreciated.



  • @fred-zept said in Replacing word between commas not included in a list of words:

    I’m wondering whether it is possible to replace any word, between the 22nd and the 23rd comma, different from these list of words

    Your 1 example line looks like a database record, possibly saved into a CSV file. I note that one of the fields is a text field and has " around it. Because of that it won’t be a simple task of counting the number of commas as any within the text fields must be excluded. That will complicate any solution. However I also note that there is the “euro” sign beyond where you want to insert a word so possibly that could be used as a reference. Could you provide the same example line with the word you do want to insert. it would help to know exactly where this position is and possibly also a bit more about what words you want to use.

    You also ask whether any word “different from a list of words”, what do you mean. Are you saying the word CANNOT be any from this list? Given the regular expression needs to know what word it WILL use, excluding words is not a problem. How do you determine what word you DO want to use?

    Terry



  • @fred-zept

    I might be tempted to solve it with a simpler scenario that could be translated to yours.

    Start with this comma-separated list of names:

    bill,bob,joe,steve,alan,karen,ryan,carolyn
    bob,joe,steve,alan,karen,ryan,carolyn,bill
    joe,steve,alan,karen,ryan,carolyn,bill,bob
    steve,alan,karen,ryan,carolyn,bill,bob,joe
    

    Say we want to replace the name after the 3rd comma with JIMMY, but only if the name that is currently there is not alan nor karen.

    So if we use this replacement:

    find: ^((([^,]+),){3}(?!alan|karen))([^,]+)
    repl: ${1}JIMMY
    search mode: reg expr

    We obtain:

    bill,bob,joe,JIMMY,alan,karen,ryan,carolyn
    bob,joe,steve,alan,karen,ryan,carolyn,bill
    joe,steve,alan,karen,ryan,carolyn,bill,bob
    steve,alan,karen,JIMMY,carolyn,bill,bob,joe
    

    It is not that difficult to translate that solution into one that would meet your need, as described, unless of course something has been misrepresented or additional complications such as those Terry mentions occur.

    Note also that I didn’t use “non-capturing” parentheses in certain places I could have. For people new to regular expressions, that just makes it harder to look at and decipher.



  • @fred-zept said in Replacing word between commas not included in a list of words:

    below the text I’d wish to get help with.

    Anytime a text field occurs in this situation that has quotes (") around it, it can mean that the field may include the same character as is used to delimit the field, in this case the comma (,). I’ve been doing some testing to determine how to exclude the , within text fields, yet be able to count the number of fields correctly. I think I now have that sorted. So the next step was to identify the records which contain one of the list of words you provided and replace ONLY that field with “altri” which is what I assume you mean.

    I think the first issue I had was understanding what you mean. I recall we had a similar issue with a previous post of your’s trying to understand “near duplicates”.

    So even though I could correctly idenity the 22nd/23rd comma what I’m unable to do successfully is replace the field if one of those words exist. So what I think is a better option is to split the process up into a number of steps.

    1. Split the lines at the 22nd field, so that any of the possible words will be at the start of a line.
    2. Identify those lines and replace ONLY that field.
    3. Combine the split lines back together.

    So we have:

    1. Use the Replace function
      Find What:(?-s)^(("?)[^"]*?\2,){22}
      Replace With:$0=\r\n=

    2. Use the Replace function to find any of the words listed and replace them.
      Find What:^=(bianco|nero|rosso|giallo|blu|verde|arancione|grigio|viola|marrone|beige|bordeaux)
      Replace With:=Altri

    3. Combine the lines back together.
      Use the Replace Function
      Find What:=(\R)=
      Replace With: empty field here.

    Hope this helps.
    Terry



  • @Terry-R said in Replacing word between commas not included in a list of words:

    So even though I could correctly idenity the 22nd/23rd comma what I’m unable to do successfully is replace the field if one of those words exist.

    @guy038 @Alan-Kilborn @PeterJones You may be wondering why I broke this into a number of steps. My original regex was a combination of 1. and 2. and I had the dreaded buffer overflow issue (presumably?), the whole file contents were selected. On the first find it worked, then second find grabbed all the file contents. The one we normally ONLY see when there are a large number of lines with a rarity of the values we are looking for in a lookahead. I don’t understand why since I only had 3 lines I was testing on, of which only 1 (1st test line) had one of the key words.

    I’ve never had this issue before on such a small test set and wondered if any of you might be able to shed light on it. I do suspect it might be related to the {22} in my regex, but that’s the extent of my thoughts. Given the problem it was just easier to break the solution in multiple steps.

    Terry

    PS in case you wanted to see exactly what I was using here it is:

    https://url.com,,27305664219,10300104,https://images.url.com/products/jacket-original-piumino-smanicato-grigio-colorblock/20870943-1-asphalt?$XXL$,"Gilet di Brand Bello indossare una giacca nuova! Modello a blocchi di colore Collo a imbuto Chiusura con zip Etichetta con logo Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata",,38.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-originals-piumino-smanicato-grigio-colorblock%2F20870943-1-asphalt%3F%24XXL%24&feedId=36675&k=40c130faec57ad6220fdad81baad41e935cc3845,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-originals-piumino-smanicato-grigio-colorblock/prd/20870943?browseCountry=IT&browseCurrency=EUR,text here,,EUR38.99,36675,"jack & jones",Grigio,,23527,,,,,"38.99 €","0.00 €",,,
    https://url.com,"text - text",27305664219,,,"Gilet di Brand Bello indossare una giacca nuova! Modello a blocchi di, colore Collo, a imbuto Chiusura con zip Etichetta con logo Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e Cappotti > Gilet",,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-originals-piumino-smanicato-grigio-colorblock%2F20870943-1-asphalt%3F%24XXL%24&feedId=36675&k=40c130faec57ad6220fdad81baad41e935cc3845,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-originals-piumino-smanicato-grigio-colorblock/prd/20870943?browseCountry=IT&browseCurrency=EUR,,,,,"jack & jones",Grigo,,23527,,,,,"38.99 €","0.00 €",,,
    https://url.com,"text - text",27305664219,10300104,https://images.url.com/products/jacket-original-piumino-smanicato-grigio-colorblock/20870943-1-asphalt?$XXL$,"Gilet di Brand Bello indossare una giacca nuova! Modello a blocchi di colore Collo a imbuto Chiusura con zip Etichetta con, logo Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e Cappotti > Gilet",38.99,"Asos.com IT,",9606,"Men's, Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-originals-piumino-smanicato-grigio-colorblock%2F20870943-1-asphalt%3F%24XXL%24&feedId=36675&k=40c130faec57ad6220fdad81baad41e935cc3845,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-originals-piumino-smanicato-grigio-colorblock/prd/20870943?browseCountry=IT&browseCurrency=EUR,,,EUR38.99,36675,"jack, & jones",,,23527,,,,,"38.99 €","0.00 €",,,
    

    and the Find What regex was (?-s)^(("?)[^"\r\n]*?\2,){22}(bianco|nero|rosso|giallo|blu|verde|arancione|grigio|viola|marrone|beige|bordeaux)
    I added the \r\n in another attempt, but the same result, whole file selected on 2nd find. Note the 2nd line has Grigo, not Grigio, I removed the i.



  • Hi guys, THANKS A LOT for your help. I’m sorry if I haven’t replied earlier, that’s the side effect of living on the other side of the planet.

    @Alan-Kilborn Thanks Alan for your suggestion but it doesn’t seem to work on my text string.

    @Terry-R said in Replacing word between commas not included in a list of words:

    looks like a database record, possibly saved into a CSV file
    Correct, this is just one of the houndred thousand of lines that populates a CSV files.

    Each line is a clothing item with its own color.
    The manufacturers have different standards for colours, of course they have the classic colours such as white, blue, yellow etc.
    Some of them have fancy names like “cosmic blue” or “burnt olive grey”.

    My goal is to target all the words that are not listed on the classic colours (bianco, rosso, giallo…) and replace them with the word “others” (altri).

    @Terry-R said in Replacing word between commas not included in a list of words:

    Are you saying the word CANNOT be any from this list?
    Exactly, the word must be different from the list of the classic colours.

    I tried your 3 steps suggestion but it does the opposite I need. It changes the words from the list in the word “altri”, and leave as they are any other word.

    Given the 5 strings below, I should get “altri” on the first two , and leave as they are the others.

    Thank you very much.

    https://www.awin1.com/pclick.php?p=27545432277&a=357849&m=9606,"Jack & Jones - Piumino smanicato verde",27545432277,10376888,https://images.asos-media.com/products/jack-jones-piumino-smanicato-verde/21025644-1-dustyolive?$XXL$,"Gilet di Jack & Jones Le maniche sono sopravvalutate Collo alto Senza maniche Chiusura con zip Logo applicato sul torace Tasche con zip ai lati Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Saldi > Giacche e Cappotti",30.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-piumino-smanicato-verde%2F21025644-1-dustyolive%3F%24XXL%24&feedId=36675&k=c025ee86b55779a9b1bf35cda2bf257a5f636709,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-piumino-smanicato-verde/prd/21025644?browseCountry=IT&browseCurrency=EUR,,,EUR30.99,36675,"jack & jones",Cosmic,,23527,,,,,"30.99 €","56.99 €",,,
    https://www.awin1.com/pclick.php?p=27577712641&a=357849&m=9606,"Hollister - Piumino smanicato nero con logo",27577712641,10445580,https://images.asos-media.com/products/hollister-piumino-smanicato-nero-con-logo/21162914-1-black?$XXL$,"Gilet di Hollister Le maniche sono sopravvalutate Modello imbottito Chiusura con zip Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e cappotti > Gilet",64.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fhollister-piumino-smanicato-nero-con-logo%2F21162914-1-black%3F%24XXL%24&feedId=36675&k=1947edd8eabd2ec2622a871a1440bb3de34d17f9,EUR,,0.00,https://www.asos.com/it/hollister/hollister-piumino-smanicato-nero-con-logo/prd/21162914?browseCountry=IT&browseCurrency=EUR,,,EUR64.99,36675,Hollister,Violetto,,25563,,,,,"64.99 €","0.00 €",,,
    https://www.awin1.com/pclick.php?p=27079248909&a=357849&m=9606,"Hi-Tec - Piumino smanicato arancione e nero",27079248909,9882602,https://images.asos-media.com/products/hi-tec-piumino-smanicato-arancione-e-nero/20030243-1-washedblack?$XXL$,"Smanicato di Hi-Tec Meglio senza maniche Modello ripiegabile Modello a blocchi di colore Chiusura con zip Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Saldi > Giacche e Cappotti",27.00,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fhi-tec-piumino-smanicato-arancione-e-nero%2F20030243-1-washedblack%3F%24XXL%24&feedId=36675&k=56358ea7d9f53a6f9fd42cba4340e9c60256afff,EUR,,0.00,https://www.asos.com/it/hi-tec/hi-tec-piumino-smanicato-arancione-e-nero/prd/20030243?browseCountry=IT&browseCurrency=EUR,,,EUR27.00,36675,Hi-Tec,Nero,,7432,,,,,"60.00 €","0.00 €",,,
    https://www.awin1.com/pclick.php?p=27733409907&a=357849&m=9606,"Gant - Piumino smanicato leggero blu navy",27733409907,10688333,https://images.asos-media.com/products/gant-piumino-smanicato-leggero-blu-navy/21647662-1-eveningblue?$XXL$,"Gilet di GANT Scopri i vantaggi Collo a imbuto Senza maniche Chiusura con zip Logo sul torace Tasche laterali con zip Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e cappotti > Gilet",179.00,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fgant-piumino-smanicato-leggero-blu-navy%2F21647662-1-eveningblue%3F%24XXL%24&feedId=36675&k=e1ef9ecc2bd92d3ce801e01083b1592fa7991727,EUR,,0.00,https://www.asos.com/it/gant/gant-piumino-smanicato-leggero-blu-navy/prd/21647662?browseCountry=IT&browseCurrency=EUR,,,EUR179.00,36675,Gant,Blu,,6422,,,,,"179.00 €","0.00 €",,,
    https://www.awin1.com/pclick.php?p=26541790687&a=357849&m=16631,"GANT SMANICATO UOMO BEIGE",26541790687,232358,https://images.pricy.it/s/232358/or/159048177822.jpg,"Scopri l'Offerta GANT SMANICATO UOMO BEIGE ed Acquista al Miglior Prezzo!Descrizione: Smanicato reversibile, automatici, 2 tasche interne e 2 tasche interne, logoComposizione:TESSUTO ESTERNO: 60% ACRILICO 40% POLIESTERE. FODERA: 61% COTONE 39% POLIAMMIDE. IMBOTTITURA: 90% PIUMINO 10% PIUMAStagione: Autunno/Inverno",UOMO;Abbigliamento;Capispalla;Smanicati,164.60,"Pricy IT",16631,,0,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.pricy.it%2Fs%2F232358%2For%2F159048177822.jpg&feedId=30757&k=19920d0dfde75e326137169d071ccf2a8418fc4a,EUR,,0,https://www.awin1.com/pclick.php?p=26541790687&a=357849&m=16631,,,EUR164.60,30757,Gant,Beige,,6422,,,,,,466.50,,,
    https://www.awin1.com/pclick.php?p=27721114437&a=357849&m=9606,"Free Country - Piumino smanicato grigio",27721114437,10411870,https://images.asos-media.com/products/free-country-piumino-smanicato-grigio/21095522-1-grey?$XXL$,"Gilet di Free Country Il prossimo articolo nei tuoi prodotti salvati Collo a imbuto Chiusura con zip Senza maniche Tasca con zip sul petto Tasche con zip ai lati Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Saldi > Giacche e Cappotti",34.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Ffree-country-piumino-smanicato-grigio%2F21095522-1-grey%3F%24XXL%24&feedId=36675&k=1d16dcd04d35af7437e570868f8a3b3fac0bba9c,EUR,,0.00,https://www.asos.com/it/free-country/free-country-piumino-smanicato-grigio/prd/21095522?browseCountry=IT&browseCurrency=EUR,,,EUR34.99,36675,"Free Country",Grigio,,26609,,,,,"34.99 €","70.99 €",,,
    
    
    


  • Hi @fred-zept

    Please, try the following regex, based in the expressions provided yesterday:

    Search: ^((([^,]*),){22}(?!bianco|nero|rosso|giallo|blu|verde|arancione|grigio|viola|marrone|mimetico|beige|bordeaux))([^,]+)
    Replace: ${1}altri
    

    Have fun!



  • @fred-zept said in Replacing word between commas not included in a list of words:

    I tried your 3 steps suggestion but it does the opposite I need. It changes the words from the list in the word “altri”, and leave as they are any other word.

    That is why it is so important that when you ask for search-and-replace help, you give both the data you have (“before”) and the way you want it to look when the transformation is complete (“after”). If you show before and after data, rather than making us try to interpret what you might want from descriptions, it’s easier for us to check whether we got what you want or not.

    You’re already following some of the advice (thanks for </> marking your example text as text! we appreciate it!), but I’ll quote my full boilerplate, just in case there’s more for you to glean:

    ----

    Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the </> toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.



  • Hello, @fred-zept, @terry-r, @alan-kilborn, @astrosofista, @peterjones and All,

    @terry-r,

    I first thougt that we shouldn’t bother about the possibility of having a double quote ", within a field, between two commas. Indeed, with the regex "[^"\r\n]+", I verified all zones between double quotes of the first @fred-zept’s sample and everything was OK

    However, in his second sample code of six lines, the 5th line contains a field between double quotes, with some commas inside ! So , we must take this fact in account !

    I’ve already noticed that the OP’s request was the opposite as he wants to replace, between the 22th and the 23th commas, any color, DIFFERENT from any color of the list, with the altri value !


    My solution is similar to the @astrosofista’s one :

    • I added, at the beginning the (?i) modifier to get a search independent of the case !

    • But I have considered, as a priority, the case of a field between quotation marks. Else, it’s a classical field, located between commas

    • I use the \K syntax

    • I preferred to insert \r\n in the negative class characters [^.....]

    • At the end of the regex, I use the * quantifier, instead of + because a field may be empty

    Giving this S/R :

    SEARCH (?i)^(?:(?:"[^"\r\n]+"|[^,\r\n]*){1}+,){22}\K(?!bianco|nero|rosso|giallo|blu|verde|arancione|grigio|viola|marrone|mimetico|beige|bordeaux)[^,\r\n]*

    REPLACE altri

    Remark : You may have noticed the {1}+ atomic quantifier. This is needed ! Let’s imagine that :

    • A line contains, somewhere, a field between double quotes "......."

    • This line also contains a color, from the list, between the 22th and the 23th commas

    As the regex engine is trying hard to find a color different from one of the list, because of the negative look-ahead, then it would backtrack and test the second alternative [^,\r\n]* ,from the part (?:"[^"\r\n]+"|[^,\r\n]*){1}+ , for a classical field, leading, finally, to a wrong result for the 23th field !

    Now, adding the atomic quantifier {1}+, this prevents the regex engine from backtracking,. So it keeps the first alternative "[^"\r\n]+" which leads to a color, between the 22th and the 23th commas, being within the list . Thus, the current line does not satisfy the overall regex and the regex engine skips to the next line. Logical !


    Here’s the output, produced from the @terry-r’s example of three lines ( two modifications in the last two lines ) :

    https://url.com,,27305664219,10300104,https://images.url.com/products/jacket-original-piumino-smanicato-grigio-colorblock/20870943-1-asphalt?$XXL$,"Gilet di Brand Bello indossare una giacca nuova! Modello a blocchi di colore Collo a imbuto Chiusura con zip Etichetta con logo Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata",,38.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-originals-piumino-smanicato-grigio-colorblock%2F20870943-1-asphalt%3F%24XXL%24&feedId=36675&k=40c130faec57ad6220fdad81baad41e935cc3845,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-originals-piumino-smanicato-grigio-colorblock/prd/20870943?browseCountry=IT&browseCurrency=EUR,text here,,EUR38.99,36675,"jack & jones",Grigio,,23527,,,,,"38.99 €","0.00 €",,,
    https://url.com,"text - text",27305664219,,,"Gilet di Brand Bello indossare una giacca nuova! Modello a blocchi di, colore Collo, a imbuto Chiusura con zip Etichetta con logo Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e Cappotti > Gilet",,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-originals-piumino-smanicato-grigio-colorblock%2F20870943-1-asphalt%3F%24XXL%24&feedId=36675&k=40c130faec57ad6220fdad81baad41e935cc3845,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-originals-piumino-smanicato-grigio-colorblock/prd/20870943?browseCountry=IT&browseCurrency=EUR,,,,,"jack & jones",altri,,23527,,,,,"38.99 €","0.00 €",,,
    https://url.com,"text - text",27305664219,10300104,https://images.url.com/products/jacket-original-piumino-smanicato-grigio-colorblock/20870943-1-asphalt?$XXL$,"Gilet di Brand Bello indossare una giacca nuova! Modello a blocchi di colore Collo a imbuto Chiusura con zip Etichetta con, logo Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e Cappotti > Gilet",38.99,"Asos.com IT,",9606,"Men's, Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-originals-piumino-smanicato-grigio-colorblock%2F20870943-1-asphalt%3F%24XXL%24&feedId=36675&k=40c130faec57ad6220fdad81baad41e935cc3845,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-originals-piumino-smanicato-grigio-colorblock/prd/20870943?browseCountry=IT&browseCurrency=EUR,,,EUR38.99,36675,"jack, & jones",altri,,23527,,,,,"38.99 €","0.00 €",,,
    


    Now, @fred-zept, if I’m using your last sample of six lines, I do get the expected result, with only the string altri placed in the two first lines, between the 22th and the 23th commas !

    https://www.awin1.com/pclick.php?p=27545432277&a=357849&m=9606,"Jack & Jones - Piumino smanicato verde",27545432277,10376888,https://images.asos-media.com/products/jack-jones-piumino-smanicato-verde/21025644-1-dustyolive?$XXL$,"Gilet di Jack & Jones Le maniche sono sopravvalutate Collo alto Senza maniche Chiusura con zip Logo applicato sul torace Tasche con zip ai lati Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Saldi > Giacche e Cappotti",30.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fjack-jones-piumino-smanicato-verde%2F21025644-1-dustyolive%3F%24XXL%24&feedId=36675&k=c025ee86b55779a9b1bf35cda2bf257a5f636709,EUR,,0.00,https://www.asos.com/it/jack-jones/jack-jones-piumino-smanicato-verde/prd/21025644?browseCountry=IT&browseCurrency=EUR,,,EUR30.99,36675,"jack & jones",altri,,23527,,,,,"30.99 €","56.99 €",,,
    https://www.awin1.com/pclick.php?p=27577712641&a=357849&m=9606,"Hollister - Piumino smanicato nero con logo",27577712641,10445580,https://images.asos-media.com/products/hollister-piumino-smanicato-nero-con-logo/21162914-1-black?$XXL$,"Gilet di Hollister Le maniche sono sopravvalutate Modello imbottito Chiusura con zip Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e cappotti > Gilet",64.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fhollister-piumino-smanicato-nero-con-logo%2F21162914-1-black%3F%24XXL%24&feedId=36675&k=1947edd8eabd2ec2622a871a1440bb3de34d17f9,EUR,,0.00,https://www.asos.com/it/hollister/hollister-piumino-smanicato-nero-con-logo/prd/21162914?browseCountry=IT&browseCurrency=EUR,,,EUR64.99,36675,Hollister,altri,,25563,,,,,"64.99 €","0.00 €",,,
    https://www.awin1.com/pclick.php?p=27079248909&a=357849&m=9606,"Hi-Tec - Piumino smanicato arancione e nero",27079248909,9882602,https://images.asos-media.com/products/hi-tec-piumino-smanicato-arancione-e-nero/20030243-1-washedblack?$XXL$,"Smanicato di Hi-Tec Meglio senza maniche Modello ripiegabile Modello a blocchi di colore Chiusura con zip Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Saldi > Giacche e Cappotti",27.00,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fhi-tec-piumino-smanicato-arancione-e-nero%2F20030243-1-washedblack%3F%24XXL%24&feedId=36675&k=56358ea7d9f53a6f9fd42cba4340e9c60256afff,EUR,,0.00,https://www.asos.com/it/hi-tec/hi-tec-piumino-smanicato-arancione-e-nero/prd/20030243?browseCountry=IT&browseCurrency=EUR,,,EUR27.00,36675,Hi-Tec,Nero,,7432,,,,,"60.00 €","0.00 €",,,
    https://www.awin1.com/pclick.php?p=27733409907&a=357849&m=9606,"Gant - Piumino smanicato leggero blu navy",27733409907,10688333,https://images.asos-media.com/products/gant-piumino-smanicato-leggero-blu-navy/21647662-1-eveningblue?$XXL$,"Gilet di GANT Scopri i vantaggi Collo a imbuto Senza maniche Chiusura con zip Logo sul torace Tasche laterali con zip Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e cappotti > Gilet",179.00,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fgant-piumino-smanicato-leggero-blu-navy%2F21647662-1-eveningblue%3F%24XXL%24&feedId=36675&k=e1ef9ecc2bd92d3ce801e01083b1592fa7991727,EUR,,0.00,https://www.asos.com/it/gant/gant-piumino-smanicato-leggero-blu-navy/prd/21647662?browseCountry=IT&browseCurrency=EUR,,,EUR179.00,36675,Gant,Blu,,6422,,,,,"179.00 €","0.00 €",,,
    https://www.awin1.com/pclick.php?p=26541790687&a=357849&m=16631,"GANT SMANICATO UOMO BEIGE",26541790687,232358,https://images.pricy.it/s/232358/or/159048177822.jpg,"Scopri l'Offerta GANT SMANICATO UOMO BEIGE ed Acquista al Miglior Prezzo!Descrizione: Smanicato reversibile, automatici, 2 tasche interne e 2 tasche interne, logoComposizione:TESSUTO ESTERNO: 60% ACRILICO 40% POLIESTERE. FODERA: 61% COTONE 39% POLIAMMIDE. IMBOTTITURA: 90% PIUMINO 10% PIUMAStagione: Autunno/Inverno",UOMO;Abbigliamento;Capispalla;Smanicati,164.60,"Pricy IT",16631,,0,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.pricy.it%2Fs%2F232358%2For%2F159048177822.jpg&feedId=30757&k=19920d0dfde75e326137169d071ccf2a8418fc4a,EUR,,0,https://www.awin1.com/pclick.php?p=26541790687&a=357849&m=16631,,,EUR164.60,30757,Gant,Beige,,6422,,,,,,466.50,,,
    https://www.awin1.com/pclick.php?p=27721114437&a=357849&m=9606,"Free Country - Piumino smanicato grigio",27721114437,10411870,https://images.asos-media.com/products/free-country-piumino-smanicato-grigio/21095522-1-grey?$XXL$,"Gilet di Free Country Il prossimo articolo nei tuoi prodotti salvati Collo a imbuto Chiusura con zip Senza maniche Tasca con zip sul petto Tasche con zip ai lati Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Saldi > Giacche e Cappotti",34.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Ffree-country-piumino-smanicato-grigio%2F21095522-1-grey%3F%24XXL%24&feedId=36675&k=1d16dcd04d35af7437e570868f8a3b3fac0bba9c,EUR,,0.00,https://www.asos.com/it/free-country/free-country-piumino-smanicato-grigio/prd/21095522?browseCountry=IT&browseCurrency=EUR,,,EUR34.99,36675,"Free Country",Grigio,,26609,,,,,"34.99 €","70.99 €",,,
    

    Best Regards,

    guy038



  • @guy038 said in Replacing word between commas not included in a list of words:

    I use the \K syntax

    @fred-zept , please note that @guy038’s solution missed one vital piece of information. As he used the \K in his regex you MUST press the “Replace All” button as this is the ONLY method of replacing the words. If using the “Replace” button no changers will be made. it is a side effect of using the \K.

    Cheers
    Terry



  • @fred-zept said in Replacing word between commas not included in a list of words:

    I tried your 3 steps suggestion but it does the opposite I need.

    Yes, that was due to the interpretation I had of your issue. I know we had a previous problem from you where again your choice of words made it difficult to understand the problem in one reading. As @PeterJones said, thanks for supplying the examples within the black boxes, and as he also said, putting in a before and after view of the examples can help immensely. Sort of like “a picture speaks a thousand words” (common saying in the English speaking world). We do know that English is not your first language from your previous problem and now you speak of being on “the other side of the planet”. Possibly we are ALL on the other side of the planet (from others).

    I’m in New Zealand (Aotearoa, Land of the Long White Cloud, God’s zone or God’s own) so in my defence I think I truly am on the other side of the planet. Given most problems pop up before I even get out of bed I’m at a disadvantage in supplying solutions. Most of the good ones are already gone! ;-))

    Cheers
    Terry



  • First of all I have to say that I’m amazed about this group and the level of competence you guys have.
    I just got the time to work on this project and here what I have found.

    @astrosofista said in Replacing word between commas not included in a list of words:

    Hi @fred-zept

    Please, try the following regex, based in the expressions provided yesterday:

    Search: ^((([^,]*),){22}(?!bianco|nero|rosso|giallo|blu|verde|arancione|grigio|viola|marrone|mimetico|beige|bordeaux))([^,]+)
    Replace: ${1}altri
    

    Have fun!

    Thanks, this seems to work on most of the lines. In some other line seems to change the value on the 21st comma rather than 22nd.
    It works on the first line, although on the second line change the word Topman, which is the brand and not the colour, rather than Pietra

    https://www.awin1.com/pclick.php?p=27397554539&a=357849&m=9606,"adidas Originals - Smanicato con 3 strisce nero",27397554539,9963546,https://images.asos-media.com/products/adidas-originals-smanicato-con-3-strisce-nero/20192202-1-black?$XXL$,"Gilet di Adidas Originals Il prossimo dei tuoi prodotti salvati Modello imbottito Collo a imbuto Logo Adidas Chiusura con zip Tasche laterali 3 strisce laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e cappotti > Gilet",74.95,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Fadidas-originals-smanicato-con-3-strisce-nero%2F20192202-1-black%3F%24XXL%24&feedId=36675&k=1f40920a1b687eb73ed4ce4da992ec98bfaf0279,EUR,,0.00,https://www.asos.com/it/adidas-originals/adidas-originals-smanicato-con-3-strisce-nero/prd/20192202?browseCountry=IT&browseCurrency=EUR,,,EUR74.95,36675,"adidas Originals",Porpora,,25479,,,,,"74.95 €","0.00 €",,,
    
    https://www.awin1.com/pclick.php?p=27250398127&a=357849&m=9606,"Topman - Piumino smanicato riciclato color pietra",27250398127,10155883,https://images.asos-media.com/products/topman-piumino-smanicato-riciclato-color-pietra/20571492-1-stone?$XXL$,"Giacca di Topman Non oggi, per quando fa freddo Collo a imbuto Senza maniche Chiusura con zip Tasca con zip sul petto Tasche laterali Vestibilità classica Veste perfettamente la taglia indicata","Uomo > Giacche e Cappotti > Gilet",55.99,"Asos.com IT",9606,"Men's Outerwear",171,https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Aimages.asos-media.com%2Fproducts%2Ftopman-piumino-smanicato-riciclato-color-pietra%2F20571492-1-stone%3F%24XXL%24&feedId=36675&k=2bd6e17c0634ad74c710a431ab947d5e483b4d4c,EUR,,0.00,https://www.asos.com/it/topman/topman-piumino-smanicato-riciclato-color-pietra/prd/20571492?browseCountry=IT&browseCurrency=EUR,,,EUR55.99,36675,Topman,Pietra,,25487,,,,,"55.99 €","0.00 €",,,
    
    

    @guy038 your solution seems to work perfectly.

    @Terry-R I guess I’m in the middle of the good ones since I live in in Europe. And you are a good one for sure Terry, I’m still using your way to delete near duplicate lines.
    Thanks again.

    Thanks everyone for your help!


Log in to reply