Post Reply 
More than one match/replace per filter?
Sep. 13, 2011, 01:05 AM (This post was last modified: Sep. 13, 2011 01:07 AM by zoltan.)
Post: #1
More than one match/replace per filter?
Say you're learning a language and want to use Proxomitron to force new vocabulary into your daily reading. It's easy to replace one word with another.

Match = "eins"
Replace = "one"

Match = "zwei"
Replace = "two"

But if you want to do it with hundreds of words and phrases, is a separate filter needed for each one, or is there a way to combine many in one filter? Or maybe a filter and list? I've experimented a bit with the $SET command but it doesn't seem suited to this purpose.
Add Thank You Quote this message in a reply
Sep. 13, 2011, 02:48 AM
Post: #2
RE: More than one match/replace per filter?
I prefer a filter and a list.

Code:
[Patterns]
Name = "Word Replace Demo"
Active = TRUE
Limit = 32
Match = "$LST(wordReplace)"
Replace = "\1"

content of $LST(wordReplace)

Code:
eins$SET(1=one)
zwei$SET(1=two)

It is just for demonstration. You may need to adjust/improve it according to your needs.
Add Thank You Quote this message in a reply
Sep. 13, 2011, 04:00 AM (This post was last modified: Sep. 13, 2011 12:20 PM by JJoe.)
Post: #3
RE: More than one match/replace per filter?
A quick bit more.

Example A
Match "$LST(Trans)"
Replace "\1"
List entries "eins $SET(\1=one)"

Problem with "A" is the list will be called every time the filter tests code and "eins" may change einstein to onetein.

Example B
Match "(\s|>)\2$LST(Trans)"
Replace "\2\1"
List entries "eins(^[a-z]) $SET(\1=one)"

Calling the list after a match has been made would speed things up. (^[a-z]) looks for the end of the word.

Example C
Match "(\s|>)\2([a-z]&$LST(Trans))"
Replace "\2\1"

Calling the list only when it may match could be better still. ([a-z]&$LST(Trans)) should call the list after a letter is found.

You could also use "(\s|>)\2(^(^[a-z]))$LST(Trans)". (^(^[a-z])) tests for but does not remove a letter, a-z.

Problem with A-C is that all text may be matched, not just rendered text.

How will you prevent matching in tags, scripts, and other 'hidden' text?

HTH
Add Thank You Quote this message in a reply
Sep. 13, 2011, 08:26 AM
Post: #4
RE: More than one match/replace per filter?
I had been experimenting with whenever's example and ran into the "einstein" issue ("ist" was contained in "bist") and spaces and punctuation before and after a word. So believe it or not I came up with this for the list:

Code:
Match = "$LST(Words)"

([^a-z])\2eins([^a-z])\3$SET(1=\2one\3)
([^a-z])\2zwei([^a-z])\3$SET(1=\2two\3)

Replace = "\1"

I was practically patting myself on the back until I came back here and saw JJoe's post.

Obviously there are some things I didn't anticipate or understand. Matching before checking the list makes sense for efficiency, but I don't understand some of examples B & C. Is the ">" for matching a tag? If so, why not "<" as well? And why are the prefix characters checked in the filter but the suffix characters checked in the list? How is the variable 2 set in example C? Is it insufficient to put ([^a-z]) before and after the word as in my example above? I assumed that all I needed was to retain and reinsert any characters that were not a-z.

If tag and script matches are limited and don't cause too many problems, I could overlook it. Just the discovery that multiple filters aren't needed makes this idea more appealing because the lone filter can be quickly unchecked when it's unwanted. Capitalization is an small issue, but I don't think Proxomitron can recognize case.
Add Thank You Quote this message in a reply
Sep. 13, 2011, 01:21 PM (This post was last modified: Sep. 13, 2011 01:25 PM by JJoe.)
Post: #5
RE: More than one match/replace per filter?
(Sep. 13, 2011 08:26 AM)zoltan Wrote:  I was practically patting myself on the back until I came back here and saw JJoe's post.

Why stop? You may continue patting. Wink

(Sep. 13, 2011 08:26 AM)zoltan Wrote:  Is the ">" for matching a tag? If so, why not "<" as well?

I think rendered words usually follow a space or a ">". Hidden and other words that shouldn't be changed may follow "<" , quotes, slashes, and other characters.

(Sep. 13, 2011 08:26 AM)zoltan Wrote:  And why are the prefix characters checked in the filter but the suffix characters checked in the list?

To reduce list calls and prevent list matches when the filter doesn't match. This should be quicker and prevent log spam.

(Sep. 13, 2011 08:26 AM)zoltan Wrote:  How is the variable 2 set in example C?

That was a editing mistake. I wrote the last filter first, added the others to explain things, and forgot to switch the positions of the variables. Sorry.

(Sep. 13, 2011 08:26 AM)zoltan Wrote:  Is it insufficient to put ([^a-z]) before and after the word as in my example above? I assumed that all I needed was to retain and reinsert any characters that were not a-z.

Retain and reinsert will work. [^a-z] might allow words in web addresses, tags, and hyphenated words to be modified.

(Sep. 13, 2011 08:26 AM)zoltan Wrote:  but I don't think Proxomitron can recognize case.

Correct.

HTH
Add Thank You Quote this message in a reply
Sep. 13, 2011, 09:37 PM (This post was last modified: Sep. 13, 2011 11:31 PM by zoltan.)
Post: #6
RE: More than one match/replace per filter?
OK, now I get most of it.
Before I can test, I'd like to understand example C better and be sure of the list entry. I see the sequence like this:

1.) Look for spaces or end of tag.
2.) if found, place in variable 2
3.) Look for a letter (of the word to be replaced)
at this point it's confusing because of the "&"
I know it means "AND" but it seems to be acting more as a conditional. "IF there's an a-z character, check the list" Is that true? And should the list entry be
"eins(^[a-z]) $SET(\1=one)" ?

I'm not sure what "(^(^[a-z]))" does differently or why it's superior to the above, since [a-z] didn't remove letters either. It seems to be nothing more than double negation, so why not just use "(\s|>)\2([a-z]$LST(Trans))"

EDIT:
After testing:
Code:
Match ="(\s|>)\2([a-z]&$LST(Trans))"
Replace = "\2\1"
List entry:  zwei(^[a-z]) $SET(\1=two)

words after parentheses are not matched
spaces after words are consumed, joining the replaced word with the next one.

I thought zwei(^[a-z])\3 $SET(\1=two\3)
might preserve the space after the match, but it doesn't.
Add Thank You Quote this message in a reply
Sep. 14, 2011, 12:53 AM (This post was last modified: Sep. 14, 2011 02:23 AM by JJoe.)
Post: #7
RE: More than one match/replace per filter?
(Sep. 13, 2011 09:37 PM)zoltan Wrote:  I know it means "AND" but it seems to be acting more as a conditional. "IF there's an a-z character, check the list" Is that true?

Exactly. If a-z, Then call list, Else fail.

(Sep. 13, 2011 09:37 PM)zoltan Wrote:  And should the list entry be
"eins(^[a-z]) $SET(\1=one)" ?

Should probably be "eins(^[a-z])$SET(\1=one)". Otherwise the space after "eins(^[a-z])" in the list will remove the space after "one" from the rendered text. Wink

I didn't test it. Sorry, yet again.

(Sep. 13, 2011 09:37 PM)zoltan Wrote:  I'm not sure what "(^(^[a-z]))" does differently or why it's superior to the above, since [a-z] didn't remove letters either. It seems to be nothing more than double negation, so why not just use "(\s|>)\2([a-z]$LST(Trans))"

Negation like (^this) does not consume.
"[a-z]$LST(Trans)" would consume a character before the list saw it. Wait maybe a typo. You probably meant "[a-z]&$LST(Trans)".

I don't know that "(^(^[a-z]))" is superior but it could be. I don't remember exactly how lists are handled. Testing is required.
Mostly, I mentioned it to be complete. It is a useful idea.

(Sep. 13, 2011 09:37 PM)zoltan Wrote:  words after parentheses are not matched

So
(\s|>|\(|\))\2([a-z]&$LST(Trans))
or
([\r\n >()])\2([a-z]&$LST(Trans))
?

(Sep. 13, 2011 09:37 PM)zoltan Wrote:  I thought zwei(^[a-z])\3 $SET(\1=two\3)
might preserve the space after the match, but it doesn't.

Variables capture consumable strings.
(^[a-z]) tests, it doesn't consume.
However, zwei(^([a-z])\3) might work.

HTH
Add Thank You Quote this message in a reply
Sep. 14, 2011, 07:41 AM
Post: #8
RE: More than one match/replace per filter?
Great. Now the spaces are preserved and it matches after parentheses. Thanks. I actually combined your last 2 suggestions to cover as much as possible (\r|\n|\s|>|\(|\))\2([a-z]&$LST(Trans))

Not to open another can of worms, but I found something that addresses the tag issue. It's a thread from 3 years ago that I've been trying to find. It's for changing a single word per filter, so not the same situation, but the tag issue was solved. Updated to the current example, it would look like this:

Code:
URL = "$TYPE(htm)"
Match = "(<$SET(open=1)|>$SET(open=))PrxNeverMatch"
        "|"
        "([^a-z0-9])\2"
        "zwei"
        "("
        "(s|)"
        "(\s|<|[^a-z0-9])"
        ")\1"
        "(^$TST(open=1))"
Replace = "\2one\1"

It's hard to tell - it may be inferior in some ways to the current one, but an addition is using PrxNeverMatch to cancel out matching (within a tag) for the duration that a variable is set to 1.
Hard to believe I somewhat understood it 3 yrs ago and totally forgot it.
Now using this with a list is a different matter, but it seems like it could be done.
Add Thank You Quote this message in a reply
Post Reply 


Forum Jump: