[Solved]Expression Needed
#1
Posted 24 November 2011 - 07:56 PM
ui block text("Original Text:", #originalText)
ui block text("<br><br><br>Bad Words:", #badWords)
ui block text("<br><br><br>New Text:", #newText)
set(#newText, $replace(#originalText, #badWords, ""), "Global")
I would like to examine the original text and delete any occurrences of the words in the bad words list. I am thinking I might need a regex expression for this as I want it to match whole words only (for example I don't want the "hell" deleted from "shell").
Anyone have a solution (regex or not)?
TIA,
Duane
__________________________________________
... this message has been approved by me...
#2
Posted 25 November 2011 - 09:40 PM
Here is an update, which is still not working, but I think I'm getting closer...
Any suggestions for making it function?
Thanks,
Duane
clear list(%originalText)
clear list(%badWords)
clear list(%newText)
ui block text("Original Text:", #originalText)
add item to list(%originalText, #originalText, "Delete", "Global")
ui block text("<br><br><br>Bad Words:", #badWords)
set list position(%badWords, 0)
add item to list(%badWords, #badWords, "Delete", "Global")
ui block text("<br><br><br>New Text:", #newText)
add item to list(%newText, #newText, "Delete", "Global")
set(#listTotal, $list total(%newText), "Global")
loop($list total(%badWords)) {
set(#newText, $replace(#originalText, $list item(%badWords, 0), ""), "Global")
increment(#listTotal)
}
__________________________________________
... this message has been approved by me...
#3
Posted 26 November 2011 - 12:15 AM
Nice and easy
ui block text("Original text", #org text)
ui block text("<BR><BR><BR>Bad words list", #bad words)
clear list(%bad words)
add list to list(%bad words, $list from text(#bad words, $new line), "Delete", "Global")
set(#temp, 0, "Global")
loop($list total(%bad words)) {
set(#org text, $replace(#org text, $list item(%bad words, #temp), $nothing), "Global")
increment(#temp)
}
Variable #org text is auto filtered to filtered text
For replacing just replace the $nothing with something you want to replace it with
Example video:
http://www.screencast.com/t/ceHtALBtc
TJ
#4
Posted 26 November 2011 - 01:05 AM
Any idea how to make it replace whole words only? For example, if "hell" is on the bad word list, I don't want to remove the "hell" from "shell" or "hello".
-Duane
__________________________________________
... this message has been approved by me...
#5
Posted 26 November 2011 - 01:41 AM
ui block text("Original text", #org text)
ui block text("<BR><BR><BR>Bad words list", #bad words)
clear list(%bad words)
add list to list(%bad words, $list from text(#bad words, $new line), "Delete", "Global")
set(#temp, 0, "Global")
loop($list total(%bad words)) {
set(#org text, $replace regular expression(#org text, "^{$list item(%bad words, #temp)}", $nothing), "Global")
increment(#temp)
}
#6
Posted 26 November 2011 - 03:46 AM
__________________________________________
... this message has been approved by me...
#7
Posted 26 November 2011 - 04:09 AM
ui block text("Original text", #org text)
ui block text("<BR><BR><BR>Bad words list", #bad words)
clear list(%bad words)
add list to list(%bad words, $list from text(#bad words, $new line), "Delete", "Global")
set(#temp, 0, "Global")
loop($list total(%bad words)) {
set(#org text, $replace regular expression(#org text, "\\b{$list item(%bad words, #temp)}\\b", $nothing), "Global")
increment(#temp)
}
load html($replace(#org text, $new line, "<BR>"))
Video example
http://screencast.com/t/BZMznuHbi
#8
Posted 26 November 2011 - 05:02 AM
Thanks again TJ!!
__________________________________________
... this message has been approved by me...
#9
Posted 26 November 2011 - 05:03 AM
#10
Posted 29 November 2011 - 10:43 PM
__________________________________________
... this message has been approved by me...
#11
Posted 30 November 2011 - 04:27 AM
You can delete the load html node, that's only for demonstration.
#12
Posted 30 November 2011 - 04:59 AM
#%&* is cool
then the the load html node will show:
is cool
while #org text will show:
<sp>is cool.
Notice the space before is, in #org text (denoted as <sp> as this board won't allow me to start a line with a space). So the load html node is further refining the results...which is what I've been unable to (but needing to) capture in a new variable. It seems TJ put some coding voodoo in ($replace(#org text, $new line, "<BR>")) that I haven't been able to duplicate. Again, I must be missing something obvious...
__________________________________________
... this message has been approved by me...
#13
Posted 01 December 2011 - 02:29 AM
set(#org text, $replace(#org text, $new line, "<BR>"), "Global")
#14
Posted 01 December 2011 - 04:31 AM
__________________________________________
... this message has been approved by me...
#15
Posted 01 December 2011 - 05:54 AM
set(#org text, $replace(#org text, $new line, $nothing), "Global")
#16
Posted 01 December 2011 - 07:00 AM
I think the problem is in the regex expression itself, it is deleting the "bad word" but needs to also delete the space that comes after the word. In the line "%#@* happens" there is a space between "%#@*" and "happens" which also needs to be deleted. I'm not sure how that would work if the "bad word" is the last word in the line though...
**UPDATE** I got it... instead of replacing it with $nothing, I replace it with ***, then I can just use a regular replace command to replace it... doh, too easy!!!
Thanks for the help, it set me to thinking on it!!!
__________________________________________
... this message has been approved by me...
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













