If I understand the RegEx ^.+userid=(\d+) correctly (which is a giant leap of faith), it is looking only for and number of digits after the “userid=” string, right?
I’m wonder if we (the ‘we’ being you), can make this more general by looking any characters between a “?” or “&” + “userid=” and “&” ?
I’m going to try to figure this out myself, but I’m sure you know it off the top of your head.
Looks like this works – will for all alphanumeric chars and underscore: ^.+[?&]userid=(\w+)&
EDIT: But this is better. It also allows for a dash ("–") character as well: ^.+[?&]userid=([\w\-]+)&
Will return X12345ABC
from this: http://www.website.com/send.aspx?b1?userid=X12345ABC&sendto=
To continue our lesson on RegEx terminology, this RegEx is returning the desired data in a Capture Group, which works well with the KM Search Variable using RegEx Action.
I know, I did it the “hard way”. LOL
OK, now show us the easy way.
Anchoring to the front of the line may be safer in some instances:
^[^=]+=([^&]+)&
Class-negation will cross vertical whitespace when you have multi-line text, so you have to account for that under some circumstances.
Here’s how you might go about this with vanilla AppleScript:
set theURL to "http://www.website.com/send.aspx?b1&userid=12345&sendto=..."
set AppleScript's text item delimiters to "="
set targetText to text item 2 of theURL
set AppleScript's text item delimiters to "&"
set targetText to text item 1 of targetText
If I were to use AppleScript and the Satimage.osax I’d probably do something like this:
set theURL to "http://www.website.com/send.aspx?b1&userid=12345xyz&sendto=..."
set targetText to change "^[^=]+=([^&]+)&.+" into "\\1" in theURL with regexp without case sensitive
The Satimage.osax’s change text is a little faster than its find text command.
On the other hand were still talking ~ ± 0.001 second, so find text might be an option:
# Using Positive Lookbehind Assertion and Positive Lookahead Assertion
set theURL to "http://www.website.com/send.aspx?b1&userid=12345xyz&sendto=..."
set targetText to find text "(?<==)[^&]+(?=&)" in theURL with regexp and string result
As Perl aficionados say: “There’s More Than One Way To Do It (TMTOWTDI or TIMTOWTDI, pronounced Tim Toady)”