Is there a way to replace a text on a dictionary on a string?

Is there a way to replace a text on a dictionary on a string?

I think to replace words inside a dictionary on a string.

I’thought about Instr to get the position of where this unwanted word appears on that string.
And replace function Or I don’t know If I’m wrong or how to combine the functions to get the final result. :frowning: :frowning:

The original String: EACH GROWING PEOPLE GET RAINING OVER THE SEAS

And the desired text: EACH PEOPLE GET OVER SEAS
Forbidden words on Dictionary: GROWING, RAINING, THE

Any Ideas?
Thanks

dim rx as new RegEx
rx.SearchPattern = "\\b(growing|raining|the)\\b\\x20*"
rx.ReplacementPattern = ""
rx.Options.ReplaceAllMatches = true

s = rx.Replace( s )
s = s.Trim

[quote=229030:@Kem Tekinay]EACH GROWING PEOPLE GET RAINING OVER THE SEAS

[/quote]
Nothing happens, that is my code(inside a module with a string return) strRFC As String:

Dim QuitaProhibidas As String
dim rx as new RegEx
rx.SearchPattern = “\b(GROWING|RAINING|THE)\b\x20*”
rx.ReplacementPattern = “”
rx.Options.ReplaceAllMatches = true

strRFC = rx.Replace( strRFC )
strRFC = strRFC.Trim

Return QuitaProhibidas.

Any suggestions?

Regex looks to be a good solution for this. I ve read The docs. Despite this doesnt do nothing, im gonna study it. Apperently there is a way to replace characters also in an array

Gerardo,

I created a test app for your help. I tried to comment extensively for you since I know much of the regEx search / replace may be new to you. This should get you pointed into the right direction. Kem and many others had helped me on this same topic so I surely wanted to try and help back. :slight_smile:

Kem had posted some ideas for regEx patterns above you can try in this app.

Please let me know if you have any questions.

https://www.dropbox.com/s/8uhe9bndqfi7znr/ReplaceTestApp.xojo_binary_project?dl=0

Thanks
Mike

[quote=229094:@Mike Cotrone]Gerardo,

I created a test app for your help. I tried to comment extensively for you since I know much of the regEx search / replace may be new to you. This should get you pointed into the right direction. Kem and many others had helped me on this same topic so I surely wanted to try and help back. :slight_smile:

Kem had posted some ideas for regEx patterns above you can try in this app.

Please let me know if you have any questions.

https://www.dropbox.com/s/8uhe9bndqfi7znr/ReplaceTestApp.xojo_binary_project?dl=0

Thanks
Mike[/quote]
Hi mike. Thanks. I have a question. If i put one word, replace all times when It the Selected word is found on the string.
But what happens if I need to filter two or more words?. How can I write it?

[quote=229266:@Gerardo García]Hi mike. Thanks. I have a question. If i put one word, replace all times when It the Selected word is found on the string.
But what happens if I need to filter two or more words?. How can I write it?[/quote]
ok I got it. I need to separe the wanted words to filter with: |.

Which character is: |?. How to type it?.
because I paste it at this time

On an English keyboard, it’s just above the “” key above the return key.

shift \ on a US keyboard

Is this what you intend? Shouldn’t you be returning “strRFC”?

Peter yes you are correct in Gerardo’s second post. Gerardo should have been returning strRFC and NOT QuitaProhibidas.

Good catch!

Yo are right i mean to write: Quitapalabras = STRRFC And then return Quitapalabras
Thanks

YEAH. I got a problem, I have a big list of unwanted word as this:

rx.SearchPattern = “\b(S C L|S.C.L.|SCL|S.A.|S. A.|A EN P|A. EN P.|A. EN P| AC|A. C.|A.C.|A.C|AC.|A. C|A C.|S. C|S N C|SNC|S.N.C.|S.N.C|S. N. C.|S.N. C.|S.N. C|S. N. C|S. N.C.|S.N. C.|S. DE R. L. DE C. V|S. DE R. L. DE C V.|S. DE R. L DE C. V|S. DE R L DE C V|S DE R L DE C V|S DE RL DE CV|S. DE R.L. DE C.V.|S. A. DE C. V.|S. A. DE C. V|S. A. DE C V|S A DE C. V.|S A DE C V|S.A. DE C.V.|S A DE C V|SA DE CV|S. A|S A|S A.|S.A|SA.|S.A.|SA|SA.|S. EN C. POR A.|S EN C. POR A.|S. EN C POR A.|S. EN C. POR A|S. EN C POR A|S EN C POR A.|S EN C POR A|CV|C.V.|C.V|CV.|S. DE RL DE CV|S. DE R.L. DE C.V.|S. DE RL. DE CV|S DE RL DE CV|S DE R L DE CV|S. DE R L DE CV|S. DE R. L. DE C. V.|R.L|R. L.|C.V.|C. V.|, |A |ANTE |BAJO |CON |CABE |CONTRA |DE |DESDE |DURANTE |EN |ENTRE |HACIA |HASTA |MEDIANTE |PARA |POR |SEGUN |SIN |SO |SOBRE |TRAS |VERSUS |VIA |EL |LA |LOS |LAS |UN |UNA |UNOS |UNAS |S. EN N.C.|S. EN N. C.|S. EN C|S EN C.|S EN NC|S. EN C.|S EN C|S. DE R.L.|S DE R L|S DE RL|S. DE R. L.|S DE R.L|S DE RL.|S. DE R.L. DE C.V.|S DE RL DE CV|S DE R L DE C V|S EN C POR A|S. EN C. POR A.|S.A.|S. A.|S A |S.N.C.|SNC|S N C|S. N. C.|A.C.|A. C.|A C|A. EN P.|A EN P|Y )\b”

All this words work. Except for S.C.L. when I want to replace it by “space” I got S.C.L. Why?

Any suggestions?

One more question if i wanna filter points?

And when I add S C to the filter list. I got L or if i add S. C. i got L. when i try to filter SCL or S.C.L.

Is it “L” A Kind of wildcard on regex?

regards

Gerardo,

Do you have RegExRx by chance? I use this to work out all of my regex patterns.
https://itunes.apple.com/us/app/regexrx/id498370702?mt=12

Thanks to all, Now I have a different question.
In order to not open a new thread.

I have my code that filter with Regex, which filter unwanted words like “s. a.” or “s. a. de c. v.” and replace with “”.
But all the filtered word are replaced by “”.

And If I want to replace each word by a new word, what should I do?
ex. “S. A. de C. V.” -> SA de CV
“S. de R. L. de C. V.” -> S de RL de CV

Thanks.

[quote=249532:@Gerardo García]Thanks to all, Now I have a different question.
In order to not open a new thread.

I have my code that filter with Regex, which filter unwanted words like “s. a.” or “s. a. de c. v.” and replace with “”.
But all the filtered word are replaced by “”.

And If I want to replace each word by a new word, what should I do?
ex. “S. A. de C. V.” -> SA de CV
“S. de R. L. de C. V.” -> S de RL de CV

Thanks.[/quote]
Gerardo,

Have you purchased RegExRx by chance? It is almost critical when trying to solve regex pattern questions. I couldn’t live without it when trying to create new regex patterns. You can do a bunch or trial and error using this tool which helps tremendously!

OS X:
https://itunes.apple.com/us/app/regexrx/id498370702?mt=12

Direct Web Site (Windows/OS X)
http://www.mactechnologies.com/index.php?page=downloads

@Kem Tekinay is the Author of RegExRx and is such an expert on the topic of Regular Expressions.

Good luck and it will be the best Five USD you will ever spend IMO.