Jump to content


Photo

[Solved]Expression Needed


  • Please log in to reply
15 replies to this topic

#1 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 24 November 2011 - 07:56 PM

For this simple code:

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

ola.gif


#2 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 25 November 2011 - 09:40 PM

Okay, I seem to have stumped the panel... Posted Image

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

ola.gif


#3 LoWrIdErTJ - BotGuru

LoWrIdErTJ - BotGuru

    Botguru.net

  • Moderators
  • 3248 posts
  • LocationMichigan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 26 November 2011 - 12:15 AM

Here you go..

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

Web Automation Bots @ BotGuru.net Want a Custom bot? click here or Email me
rjr.jpg

botgurusecured-banner.png

 


#4 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 26 November 2011 - 01:05 AM

Ah... thanks, TJ! I keep forgetting the $nothing variable... I was just leaving it blank.

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

ola.gif


#5 LoWrIdErTJ - BotGuru

LoWrIdErTJ - BotGuru

    Botguru.net

  • Moderators
  • 3248 posts
  • LocationMichigan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 26 November 2011 - 01:41 AM

Like this with regex


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


Web Automation Bots @ BotGuru.net Want a Custom bot? click here or Email me
rjr.jpg

botgurusecured-banner.png

 


#6 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 26 November 2011 - 03:46 AM

I understand the logic, but this is not doing anything for me... is it the right regex? Posted Image

__________________________________________

... this message has been approved by me...

ola.gif


#7 LoWrIdErTJ - BotGuru

LoWrIdErTJ - BotGuru

    Botguru.net

  • Moderators
  • 3248 posts
  • LocationMichigan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 26 November 2011 - 04:09 AM

Slight change in regex

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

Web Automation Bots @ BotGuru.net Want a Custom bot? click here or Email me
rjr.jpg

botgurusecured-banner.png

 


#8 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 26 November 2011 - 05:02 AM

Ah... that time you nailed it! Awesome!!

Thanks again TJ!!

Posted Image

__________________________________________

... this message has been approved by me...

ola.gif


#9 LoWrIdErTJ - BotGuru

LoWrIdErTJ - BotGuru

    Botguru.net

  • Moderators
  • 3248 posts
  • LocationMichigan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 26 November 2011 - 05:03 AM

no problem your welcome.

Web Automation Bots @ BotGuru.net Want a Custom bot? click here or Email me
rjr.jpg

botgurusecured-banner.png

 


#10 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 29 November 2011 - 10:43 PM

I've been scratching my head trying to figure out how to include the regexed replacement to a variable... currently it writes to the screen, how would I get it to either overwrite the #org text variable or create a new one? The way its written (loading to html) is interesting... but I don't understand how to load to a variable instead... I must be missing something really basic here... Posted Image

__________________________________________

... this message has been approved by me...

ola.gif


#11 odeesuba

odeesuba

    Advanced Member

  • UBot Users
  • PipPipPip
  • 140 posts
  • OS:Windows 7
  • Total Memory:4Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 30 November 2011 - 04:27 AM

Its already changing the variable #org text, monitor it in the debugger.

You can delete the load html node, that's only for demonstration.

#12 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 30 November 2011 - 04:59 AM

The variable #org text is partially changing, but not completely. For example, if the bad word is the first word in the line:

#%&* 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...Posted Image

__________________________________________

... this message has been approved by me...

ola.gif


#13 odeesuba

odeesuba

    Advanced Member

  • UBot Users
  • PipPipPip
  • 140 posts
  • OS:Windows 7
  • Total Memory:4Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 01 December 2011 - 02:29 AM

if the load html is doing the trick try to set the variable with the replace as TJ did


set(#org text, $replace(#org text, $new line, "<BR>"), "Global")


#14 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 01 December 2011 - 04:31 AM

Thanks... I've tried that and it results with all the literal <BR>s instead of line breaks. I tried cleaning that up as well and that led me back to thinking there must be an easier way to do it all in one go...

__________________________________________

... this message has been approved by me...

ola.gif


#15 odeesuba

odeesuba

    Advanced Member

  • UBot Users
  • PipPipPip
  • 140 posts
  • OS:Windows 7
  • Total Memory:4Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 01 December 2011 - 05:54 AM

what about this

set(#org text, $replace(#org text, $new line, $nothing), "Global")


#16 Legend

Legend

    Advanced Member

  • UBot Users
  • PipPipPip
  • 1454 posts
  • LocationJapan
  • OS:Windows 7
  • Total Memory:8Gb
  • Framework:v3.5 & v4.0
  • License:Dev

Posted 01 December 2011 - 07:00 AM

Then its all on one line with no line breaks...

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... Posted Image

**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!!! Posted Image

__________________________________________

... this message has been approved by me...

ola.gif





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users