cob007 19 Posted January 15, 2020 Report Share Posted January 15, 2020 Hello, I have the following sentence and from this sentence I want to remove the words , and and ofhowever it also ends up removing the word and from understand and of from coffee So in such case how to use regex to remove specific word but not the words for which it is also part of like understand and coffee from a single list item =============================add item to list(%word,"It was easy to understand and really makes you think about choices you\'ve made in your life. It\'ll be on and of my coffee table for family and friends to peruse.","Don\'t Delete","Global") Quote Link to post Share on other sites
charliefinale 5 Posted January 15, 2020 Report Share Posted January 15, 2020 The basic form is add item to list(%new list,$replace regular expression("however it also ends up removing the word and from understand and of from coffee","and of"," "),"Don\'t Delete","Global") If you want to do the words one at a time then you would need to loop through them from another list of words that you want to remove. Quote Link to post Share on other sites
bestmacros 60 Posted January 15, 2020 Report Share Posted January 15, 2020 clear list(%word) add item to list(%word,"It was easy to understand and really makes you think about choices you\'ve made in your life. It\'ll be on and of my coffee table for family and friends to peruse.","Don\'t Delete","Global") set(#fixed word,$replace regular expression($list item(%word,0),"\\sand\\sof",$nothing),"Global") alert(#fixed word) Quote Link to post Share on other sites
cob007 19 Posted January 15, 2020 Author Report Share Posted January 15, 2020 clear list(%word) add item to list(%word,"It was easy to understand and really makes you think about choices you\'ve made in your life. It\'ll be on and of my coffee table for family and friends to peruse.","Don\'t Delete","Global") set(#fixed word,$replace regular expression($list item(%word,0),"\\sand\\sof",$nothing),"Global") alert(#fixed word)Thank macro but i wanted to get rid of all the ands and the one after understand, only the later and i was able to ger rid of It was easy to understand and really Quote Link to post Share on other sites
bestmacros 60 Posted January 15, 2020 Report Share Posted January 15, 2020 clear list(%word) add item to list(%word,"It was easy to understand and really makes you think about choices you\'ve made in your life. It\'ll be on and of my coffee table for family and friends to peruse.","Don\'t Delete","Global") set(#fixed word,$replace regular expression($list item(%word,0),"(\\sand|\\sof)",$nothing),"Global") alert(#fixed word)removes all "and" and "of" Quote Link to post Share on other sites
cob007 19 Posted January 16, 2020 Author Report Share Posted January 16, 2020 clear list(%word) add item to list(%word,"It was easy to understand and really makes you think about choices you\'ve made in your life. It\'ll be on and of my coffee table for family and friends to peruse.","Don\'t Delete","Global") set(#fixed word,$replace regular expression($list item(%word,0),"(\\sand|\\sof)",$nothing),"Global") alert(#fixed word)removes all "and" and "of" thanks that was great simple solution Quote Link to post Share on other sites
cob007 19 Posted January 19, 2020 Author Report Share Posted January 19, 2020 clear list(%word) add item to list(%word,"It was easy to understand and really makes you think about choices you\'ve made in your life. It\'ll be on and of my coffee table for family and friends to peruse.","Don\'t Delete","Global") set(#fixed word,$replace regular expression($list item(%word,0),"(\\sand|\\sof)",$nothing),"Global") alert(#fixed word)removes all "and" and "of" what if i also want to remove the first word 'it' because then i cant use space if i use \sit , although it will remove all the 'its' from sentences but then what if it occurs as first word then there is no space in the beginnng of first word, so it is not able to remove the it from the first word of sentence Quote Link to post Share on other sites
HelloInsomnia 1103 Posted January 19, 2020 Report Share Posted January 19, 2020 what if i also want to remove the first word 'it' because then i cant use space if i use \sit , although it will remove all the 'its' from sentences but then what if it occurs as first word then there is no space in the beginnng of first word, so it is not able to remove the it from the first word of sentence This will remove "it" - even if it's the first word: (?i)(^it|it) But because of the spaces, and the It'll which will leave the 'll then probably a better solution would be: (?i)(^it|it)[^\s\.\,\;]*\s? This will ignore the case, then look for it with the start of the line (or not) followed by any characters except space, period, comma, semi-colon then followed by a space (maybe). Quote Link to post Share on other sites
cob007 19 Posted January 19, 2020 Author Report Share Posted January 19, 2020 This will remove "it" - even if it's the first word: (?i)(^it|it) But because of the spaces, and the It'll which will leave the 'll then probably a better solution would be: (?i)(^it|it)[^\s\.\,\;]*\s? This will ignore the case, then look for it with the start of the line (or not) followed by any characters except space, period, comma, semi-colon then followed by a space (maybe).(?i)(^it|it) Thanks nick, but then i have these as variabls, so sometimes i have ''and and sometimes it, of, the etc which are considered as stop words. so if user chooses and and then if we use this command (?i)(^it|it) then it removes the and from the understand as well if we replace that it with and So it is just one choice, if user chooses and, then the and should get removed on its own or if the entire sentence starts with and but it should not remove the word and from the understand. Quote Link to post Share on other sites
cob007 19 Posted January 20, 2020 Author Report Share Posted January 20, 2020 (?i)(^it|it) Thanks nick, but then i have these as variabls, so sometimes i have ''and and sometimes it, of, the etc which are considered as stop words. so if user chooses and and then if we use this command (?i)(^it|it) then it removes the and from the understand as well if we replace that it with and So it is just one choice, if user chooses and, then the and should get removed on its own or if the entire sentence starts with and but it should not remove the word and from the understand.to give proper example, the user can choose any stop word to remove like and, of, the, it etc and these stop words can be in beginning or middle of sentences, so im using a variable to represent stop word.Now these stop words unfortunately can be part of words; like of is found in coffee and and is found in understand and it is found in it''llThe it'll is a bit more forgiving and understandable than removing and from understand and of from coffeee. i think is it best to have each word as a seperate list item in a list and then look for what stop word to remove than have them in a single list item as a sentence the way i have it now Quote Link to post Share on other sites
HelloInsomnia 1103 Posted January 20, 2020 Report Share Posted January 20, 2020 Maybe something like this, change the red parts. (?i)(\bit['a-zA-Z]*[\s\,\;]*|\sit['a-zA-Z]*(?=\.)) Quote Link to post Share on other sites
HelloInsomnia 1103 Posted January 20, 2020 Report Share Posted January 20, 2020 By the way you can use multiple words like so, just keep adding more with a pipe separator: (?i)(\b(of|it)['a-zA-Z]*[\s\,\;]*|\s(of|it)['a-zA-Z]*(?=\.)) Quote Link to post Share on other sites
cob007 19 Posted January 20, 2020 Author Report Share Posted January 20, 2020 By the way you can use multiple words like so, just keep adding more with a pipe separator: (?i)(\b(of|it)['a-zA-Z]*[\s\,\;]*|\s(of|it)['a-zA-Z]*(?=\.))thanks nick, that has all worked really properly nowbut say there is a word like well-written and there is word like well somewhere else so we should escape \- in that case so that only well gets removed and not the well from well-written Quote Link to post Share on other sites
HelloInsomnia 1103 Posted January 21, 2020 Report Share Posted January 21, 2020 To remove well- from well-written: (?i)(\b(of|it|well)['a-zA-Z]*[\s\,\;]*-?|\s(of|it|well)['a-zA-Z]*(?=\.)) 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.