From: Jim Janney on 20 May 2010 16:14 Daniel Pitts <newsgroup.spamfilter(a)virtualinfinity.net> writes: > On 5/20/2010 10:26 AM, Jim Janney wrote: >> Jimmy<jimmy_please(a)yahoo.com> writes: >> >>> Below are the example of possible input strings: >>> >>> myparam1=myvalue1¶m1=value2¶m3=value3 >>> &myparam1=myvalue1¶m1=value2¶m3=value3 >>> ?myparam1=myvalue1¶m1=value2¶m3=value3 >>> "myparam1=myvalue1¶m1=value2¶m3=value3" >>> "&myparam1=myvalue1¶m1=value2¶m3=value3" >>> "?myparam1=myvalue1¶m1=value2¶m3=value3" >>> >>> I like to replace value of "param1" with "somevalue". Can it be done >>> in 1 expression replacement? Cuz pattern [\"&?]* works for searching, >>> but reusing the same pattern will get rid of the first non-alpha >>> character. >> >> >> String input = "&myparam1=myvalue1¶m1=value2¶m3=value3"; >> String replaced = input.replaceAll("\\bparam1=\\w+", "param1=somevalue"); >> > Sounds good unless value2 is actually "abc%2C123", in which case \\w+ > won't properly match. > > Like I've said elsewhere, the least fragile approach is to actually > parse the string and re-create it. Regex hacks might work, but they > might fail in unexpected ways. Not present in the sample data, but the problem is underspecified. -- Jim Janney
From: Daniel Pitts on 20 May 2010 17:46 On 5/20/2010 1:14 PM, Jim Janney wrote: > Daniel Pitts<newsgroup.spamfilter(a)virtualinfinity.net> writes: > >> On 5/20/2010 10:26 AM, Jim Janney wrote: >>> Jimmy<jimmy_please(a)yahoo.com> writes: >>> >>>> Below are the example of possible input strings: >>>> >>>> myparam1=myvalue1¶m1=value2¶m3=value3 >>>> &myparam1=myvalue1¶m1=value2¶m3=value3 >>>> ?myparam1=myvalue1¶m1=value2¶m3=value3 >>>> "myparam1=myvalue1¶m1=value2¶m3=value3" >>>> "&myparam1=myvalue1¶m1=value2¶m3=value3" >>>> "?myparam1=myvalue1¶m1=value2¶m3=value3" >>>> >>>> I like to replace value of "param1" with "somevalue". Can it be done >>>> in 1 expression replacement? Cuz pattern [\"&?]* works for searching, >>>> but reusing the same pattern will get rid of the first non-alpha >>>> character. >>> >>> >>> String input = "&myparam1=myvalue1¶m1=value2¶m3=value3"; >>> String replaced = input.replaceAll("\\bparam1=\\w+", "param1=somevalue"); >>> >> Sounds good unless value2 is actually "abc%2C123", in which case \\w+ >> won't properly match. >> >> Like I've said elsewhere, the least fragile approach is to actually >> parse the string and re-create it. Regex hacks might work, but they >> might fail in unexpected ways. > > Not present in the sample data, but the problem is underspecified. Agreed, but problems are *often* underspecified in the real world. While a programmers job may be to implement a exact specification, an engineers job is to extract that specification from inexact user requests. If Jimmy (the OP) only wanted to replace param1=value2 with param2=somevalue, in the given "sample" data, he could have done so manually once. It was fairly clear, with some experience in the field, what his actual problem domain was. It *is* possible that I've made a mistake, since I've made assumptions about the request. However, by providing a solution, and explaining the assumptions, we have provided a path forward in the conversation. If my assumptions are correct, then my solution will be useful to the OP. If my assumptions are incorrect, then the OP can correct them and that process is useful to everyone participating in the conversation. -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
From: Jim Janney on 20 May 2010 18:21 Daniel Pitts <newsgroup.spamfilter(a)virtualinfinity.net> writes: > On 5/20/2010 1:14 PM, Jim Janney wrote: >> Daniel Pitts<newsgroup.spamfilter(a)virtualinfinity.net> writes: >> >>> On 5/20/2010 10:26 AM, Jim Janney wrote: >>>> Jimmy<jimmy_please(a)yahoo.com> writes: >>>> >>>>> Below are the example of possible input strings: >>>>> >>>>> myparam1=myvalue1¶m1=value2¶m3=value3 >>>>> &myparam1=myvalue1¶m1=value2¶m3=value3 >>>>> ?myparam1=myvalue1¶m1=value2¶m3=value3 >>>>> "myparam1=myvalue1¶m1=value2¶m3=value3" >>>>> "&myparam1=myvalue1¶m1=value2¶m3=value3" >>>>> "?myparam1=myvalue1¶m1=value2¶m3=value3" >>>>> >>>>> I like to replace value of "param1" with "somevalue". Can it be done >>>>> in 1 expression replacement? Cuz pattern [\"&?]* works for searching, >>>>> but reusing the same pattern will get rid of the first non-alpha >>>>> character. >>>> >>>> >>>> String input = "&myparam1=myvalue1¶m1=value2¶m3=value3"; >>>> String replaced = input.replaceAll("\\bparam1=\\w+", "param1=somevalue"); >>>> >>> Sounds good unless value2 is actually "abc%2C123", in which case \\w+ >>> won't properly match. >>> >>> Like I've said elsewhere, the least fragile approach is to actually >>> parse the string and re-create it. Regex hacks might work, but they >>> might fail in unexpected ways. >> >> Not present in the sample data, but the problem is underspecified. > Agreed, but problems are *often* underspecified in the real > world. While a programmers job may be to implement a exact > specification, an engineers job is to extract that specification from > inexact user requests. > > If Jimmy (the OP) only wanted to replace param1=value2 with > param2=somevalue, in the given "sample" data, he could have done so > manually once. It was fairly clear, with some experience in the > field, what his actual problem domain was. It *is* possible that I've > made a mistake, since I've made assumptions about the > request. However, by providing a solution, and explaining the > assumptions, we have provided a path forward in the conversation. > > If my assumptions are correct, then my solution will be useful to the > OP. If my assumptions are incorrect, then the OP can correct them and > that process is useful to everyone participating in the conversation. Agreed, but we're still both guessing. What if && is supposed to represent a quoted & in a value? (Probably not, but who knows?) Without some sort of ground rules, I can take any solution and construct an input that will break it. -- Jim Janney
From: Daniel Pitts on 20 May 2010 20:02 On 5/20/2010 3:21 PM, Jim Janney wrote: > Daniel Pitts<newsgroup.spamfilter(a)virtualinfinity.net> writes: > >> On 5/20/2010 1:14 PM, Jim Janney wrote: >>> Daniel Pitts<newsgroup.spamfilter(a)virtualinfinity.net> writes: >>> >>>> On 5/20/2010 10:26 AM, Jim Janney wrote: >>>>> Jimmy<jimmy_please(a)yahoo.com> writes: >>>>> >>>>>> Below are the example of possible input strings: >>>>>> >>>>>> myparam1=myvalue1¶m1=value2¶m3=value3 >>>>>> &myparam1=myvalue1¶m1=value2¶m3=value3 >>>>>> ?myparam1=myvalue1¶m1=value2¶m3=value3 >>>>>> "myparam1=myvalue1¶m1=value2¶m3=value3" >>>>>> "&myparam1=myvalue1¶m1=value2¶m3=value3" >>>>>> "?myparam1=myvalue1¶m1=value2¶m3=value3" >>>>>> >>>>>> I like to replace value of "param1" with "somevalue". Can it be done >>>>>> in 1 expression replacement? Cuz pattern [\"&?]* works for searching, >>>>>> but reusing the same pattern will get rid of the first non-alpha >>>>>> character. >>>>> >>>>> >>>>> String input = "&myparam1=myvalue1¶m1=value2¶m3=value3"; >>>>> String replaced = input.replaceAll("\\bparam1=\\w+", "param1=somevalue"); >>>>> >>>> Sounds good unless value2 is actually "abc%2C123", in which case \\w+ >>>> won't properly match. >>>> >>>> Like I've said elsewhere, the least fragile approach is to actually >>>> parse the string and re-create it. Regex hacks might work, but they >>>> might fail in unexpected ways. >>> >>> Not present in the sample data, but the problem is underspecified. >> Agreed, but problems are *often* underspecified in the real >> world. While a programmers job may be to implement a exact >> specification, an engineers job is to extract that specification from >> inexact user requests. >> >> If Jimmy (the OP) only wanted to replace param1=value2 with >> param2=somevalue, in the given "sample" data, he could have done so >> manually once. It was fairly clear, with some experience in the >> field, what his actual problem domain was. It *is* possible that I've >> made a mistake, since I've made assumptions about the >> request. However, by providing a solution, and explaining the >> assumptions, we have provided a path forward in the conversation. >> >> If my assumptions are correct, then my solution will be useful to the >> OP. If my assumptions are incorrect, then the OP can correct them and >> that process is useful to everyone participating in the conversation. > > Agreed, but we're still both guessing. What if&& is supposed to > represent a quoted& in a value? (Probably not, but who knows?) > Without some sort of ground rules, I can take any solution and > construct an input that will break it. True, but my assumptions are that this is a standard URL, encoded with the standard %xx notation (rather than &&). Considering the prevalence of web technology (esp. with Java programming), and the frequency I've come across a similar problem, I would be more apt to believe it was as I assumed, than any other way, until proven otherwise (by the OP enlightening us all). -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
From: Arne Vajhøj on 25 May 2010 21:53
On 20-05-2010 00:04, Lew wrote: > Lew wrote: >>>>> "Cuz" is not a formal word in English.[...] > > Eric Sosman wrote: >>>> Lew's "Three R's" must have been Reading, Witing, and Ranting. >>>> God willing, someday he'll Reduce, Reuse, and Recycle the last. > > Lew: >>> Was there anything at all inaccurate in my assertion? If not, then the >>> heck with you. > > Arne Vajhøj wrote: >> I am sure that your description of what "Cuz" means >> is accurate. >> >> But that does not necessarily make it worthwhile >> to bring up in a Java programming forum. >> >> I can understand complaints about form when a post is >> hardly recognizable as English. >> >> But this one was not so bad. > > Hey, if the poster in question wants to sound like a stupid teenager > with no skills, that's their business, but they should at least be aware > of it. How many micro-ergs of energy did they save by shaving off four > characters? To me it's an indication of likely carelessness in coding > style - I mean, if you can't even be bothered to spell out "because", > how likely are they to include full Javadocs and logging in their code? > > You can be an apologist for laziness and stupid txtsp33k if you like, > but someone's got to take a stand. "Cuz" that's just how I roll, cuz. > Now to heck with you. I can understand the point if the question did sound like a stupid teenager, but it did not. It was readable English - maybe not native English (I am not qualified to judge that) but easily readable English. Cuz is not Oxford English but it seems to be a known style. http://en.wiktionary.org/wiki/because (interestingly http://en.wikipedia.org/wiki/Cuz has a term for the phenomenon "apocopation") Readable English is a good thing for questions posted here. Formal English seems like a tough requirement. Arne |