milkygirl90 wrote: ↑
4. Lastly, what is wrong with my syntax below for Else if, and why does it not clean my FB link?
Code: Select all
CleanGoogleLink() {
if RegExMatch(Clipboard, ".*google.com.*(?=&oq=)", m) {
else if RegExMatch(Clipboard, ".*fbcdn.net*(?=&bytestart=)", m)
OnClipboardChange("CleanGoogleLink", 0)
Clipboard := m
OnClipboardChange("CleanGoogleLink", 1)
}
}
If you follow the logic of the above code, when the
if condition is false, it wouldn’t drop down to the next line inside the braces, it would jump to after the closing brace, which is right before the end of the function. That's where an
else associated with that
if would have to go. So inside the braces, you just start with an
else, that had no
if associated with it. What you posted wouldn’t even run because of your syntax error (an else that doesn’t match an if), let alone not clean your FB link. The following would do what you want:
Code: Select all
CleanGoogleLink() {
OnClipboardChange("CleanGoogleLink", 0)
if RegExMatch(Clipboard, ".*google.com.*(?=&oq=)", m)
Clipboard := m
else if RegExMatch(Clipboard, ".*fbcdn.net.*(?=&bytestart=)", m) ; you were missing a "." before the second "*"
Clipboard := m
OnClipboardChange("CleanGoogleLink", 1)
}
I would do this instead:
Code: Select all
CleanGoogleLink() {
OnClipboardChange("CleanGoogleLink", 0)
Clipboard := RegExReplace(Clipboard, "google.com.*\K&oq=.*")
Clipboard := RegExReplace(Clipboard, "fbcdn.net.*\K&bytestart=.*")
OnClipboardChange("CleanGoogleLink", 1)
}
Not sure I understand your other questions.