What I am trying to do: I want something to copy a link, then search the link, then replace what is in the link with out touching the rest of the link. If that is not confusing enough.
I would like it to copy that link then remove everything between mod= and the “:”
So it would remove jp_james.
Then there would be a input so I can replace it.
I would really like it if there could be a drop down menu that would add the jp_ part of it. The drop down would have jp_/ch_/ko_. So there would be multiple choices including non.
Also maybe if it can show me what the link will be while I type the name and make my selection. then at then end a simple paste command.
I hope someone can help and understand what I just said.
Bonus: if it could remember the last name I typed so all I have to do is change the drop down menu to the correct one that would be great.
Chris, as you know I'm trying to learn RegEx. So I saw your example here as a great learning opportunity. Your solution, of course, works perfectly.
In the course of analyzing this, the following questions occured to me:
What if the URL was not a standard "http" ?
What if the post variable ("mod") was not in the first position, and thus started with a "&"
So, I experimented a little, and came up with this alternate RegEx that:
Allows the "mod" to be preceded by either "?" or "&"
Does not care what precedes that
Basically will match all characters between "mod" and ":", allow that group to be discarded while using the match groups $1 and $3 on either side of that.
In the KM Search For box: ^(.+[?&]mod=)(.+)(:.+)
In the Replace with box: $1%Variable%NewName%$3
I'd love to have your assessment of this when you have time.
For any other readers having this question, the answer is that the Variable is automatically saved in your KM variable environment. The real question is, how to show the last value of that variable in the Prompt for Input.
The answer is: enter the variable token in the default value field:
There is a second area that I have to change the name. But this area is in code. So what I did was copy the whole macro then tried to change the copy and replace (since I want it to do that same thing) but it did not work
The portion that it needs to be replace looks like this
<owner><![CDATA[James]]></owner>
So How would I tell it to find and replace where James is? Its not always going to say James. So I was trying to find and replace the following.
"owner>< /owner>
(I had to add a space after the < and before the / for it to show up in this page)
###This uses the same general RegEx pattern as before: (<owner><!\[CDATA\[)(.+)(\]\]><\/owner>)
Notice that the ( ) bound the match groups involved:
$1 -- group preceding the text you want to replace
$2 -- group that you want to replace (which can be anything: (.+)
$3 -- group following the text you want to replace
###Here's an example macro, that you should now be able to use to compose the actual macro you need:
Regular expressions will almost always have some sort of limitations when parsing URLs - the trick is really just ensuring it will match and correctly behave with the URLs that you are likely to see.
No doubt there is much I don’t understand about RegEx.
Thanks, Peter, for taking the time to edify me, and hopefully many others.
So, as I understand it, using @ccstone’s pattern of ^(http.+?mod=)[^:]+ , the following will misidentify (match): http://l.corp.help.com/help/me.php?type=testmod=jp_james:thank you
since it does NOT require either a “&” nor a “?” prior to the “mod=”.
Since the OP was looking for a post variable of “mod”, shouldn’t either a “?” or a “&” be required for a correct match?