Jump to content
UBot Underground

Regex To Remove Specific Words From Single List Item


Recommended Posts

Hello,

 

I have the following sentence and from this sentence I want to remove the words , and and of

however 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")

 

Link to post
Share on other sites

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. 

Link to post
Share on other sites
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)

 

Link to post
Share on other sites
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

Link to post
Share on other sites
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"

Link to post
Share on other sites
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

Link to post
Share on other sites
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

Link to post
Share on other sites

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).

Link to post
Share on other sites

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.

Link to post
Share on other sites

(?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''ll

The 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

Link to post
Share on other sites

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 now

but 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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...