mIRC Homepage
Posted By: Sephiroth_ $read with case sensitivity - 16/01/11 06:41 AM
Almost every thingy has it so far.

Would be very handy together with wildmask search.
Posted By: 5618 Re: $read with case sensitivity - 16/01/11 07:18 AM
You could use the r switch for a case-sensitive regex match.
That of course does mean you need to escape certain characters.
Posted By: Sephiroth_ Re: $read with case sensitivity - 16/01/11 08:40 AM
I know, i'm doing this right now.

Its just a feature request.
Posted By: Tomao Re: $read with case sensitivity - 16/01/11 11:50 PM
I think you missed 5618's point. He was pointing you to the -r switch, which is regex. And regex is case sensitive by design. I have to admit that switch is seldom used and thus it's uncommon.
Posted By: Wims Re: $read with case sensitivity - 17/01/11 12:31 AM
And I think you are the one who missed something wink
Quote:
-You could use the r switch for a case-sensitive regex match.
-I know, i'm doing this right now.
As said it's just a suggestion
Posted By: Tomao Re: $read with case sensitivity - 17/01/11 01:52 AM
Thanks for connecting the dots, Mr. Wims. tired
Posted By: argv0 Re: $read with case sensitivity - 17/01/11 02:22 AM
I'm a little confused.. what's wrong with just using the regex switch? it seems to me like the conversion between wildcard and regex is trivial enough that it shouldn't really matter. IMO if there's already a reasonable way to achieve case sensitive searching that *works*, there's no real need to add another.

FWIW: a wildcard "*" becomes ".*", "?" becomes ".?" and "&" becomes "\S+" when translating to regex.
Posted By: Sephiroth_ Re: $read with case sensitivity - 17/01/11 05:31 AM
There was also no real need for $replacex() and it was added. It just makes things easier thats all.
Posted By: argv0 Re: $read with case sensitivity - 17/01/11 09:41 AM
Actually there was a need for $replacex because there was no way to use $replace when the production of one replacement matched the value of another replacement match later on in the string, ie:

Code:
//echo -a $replacex(hello,e,l,l,x) != $replace(hello,e,l,l,x)


It was not a "convenience" addition, it added functionality that was previously not available in that identifier. This is unlike $read, which can still be used by just changing the switch from w to r and modifying the search term slightly. The functionality of case sensitive $read is still available within the same identifier.

Secondly, what is your metric for defining "easier"? The only quantitative way I can think of is to count bytes, so let's do just that:

Here is the most common wildcard scenario of matching "*foo*":

Code:
echo -a $read(file,w,*foo*)
echo -a $read(file,r,foo)


Note that the regex version is also case sensitive. The second line looks "easier" to me, there, if "easy" is defined as "fewer bytes".

The other common scenario of matching foo* or *foo turns into:

Code:
echo -a $read(file,w,foo*)
echo -a $read(file,r,^foo)


They are equivalent in byte size, so I guess neither is easier-- aka: the regex is not harder.

And here is a much less common match like *foo*bar*:

Code:
echo -a $read(file,w,*foo*bar*)
echo -a $read(file,r,foo.*bar)


The regex version is still one character shorter.

I'm not really buying that wildcard matching is any easier. Not only is the regex often shorter, but they are practically equivalent. How is the regex in any of the above examples complicated enough to warrant a new switch? Do you have a specific use case where wildcards can be considered significantly easier by any reasonable metric? If so, show an example. If you don't have a actual example of why you need this over using regex, I reiterate my confusion of why you're asking for something you have no use for.

As a sidenote, if you define "easier" as "I don't know how to write ridiculously simple regex expressions", you can always use the following short alias and continue writing wildcards:

Code:
alias wre return $+(/^,$replace($regsubex($1,/([|\/\\\[\](){}$^.])/g,\\1),*,.*,?,.,&,\S+),$!/,$2)


Then use:

Code:
echo -a $read(file,r,$wre(*foo*bar*,i))
echo -a $read(file,r,$wre(*foo*bar*))


The first line is case insensitive (the ",i" switch), and the latter is case sensitive.
Posted By: Riamus2 Re: $read with case sensitivity - 17/01/11 11:11 AM
Regex is not something that a beginner scripter is going to understand even if it really doesn't take much to convert a search to compatible regex. Beginner scripters simply aren't going to have any idea how to do it. I think having a case sensitive switch for $read() could be useful. I very rarely do anything that uses case sensitivity, so would probably never use it myself, but I don't think that telling a new scripter to use regex is a good option for them either.
Posted By: Sephiroth_ Re: $read with case sensitivity - 17/01/11 12:04 PM
Well i solved that always by replacing the first replacement thing with something that won't appear inside the string then changing the rest and so on.

There WAS no real need for $replacex(). (for me at least and it was added because someone requested it or Khaled thought "would be nice to have".)
for example:
Code:
$replace(hello,e,y,l,x,y,l)
as $replace performed the replacements after another, it was easy to bypass this problem.

Thats the same what you are trying to do now, using a "workaround".

I've just made a feature request thats all and now please stop complaining about it, i know how to use regex. As i already said before, i'm using regex at the moment for that, but it's easier for beginners or other (lazy) people.

Edit: As you can see from my example about the $replace thing, i don't care about longer or shorter scripts.
Posted By: Tomao Re: $read with case sensitivity - 17/01/11 06:11 PM
Sephiroth_, you obviously don't know the difference between $replace and $replacex. The behavior of $replace is to not ignore replacements that have already been made, $replacex doesn't do this.

Code:
//echo $replace(abcd,a,b,b,z)
will return zzcd

Code:
//echo $replacex(abcd,a,b,b,z)
will return bzcd
Posted By: Sephiroth_ Re: $read with case sensitivity - 17/01/11 06:35 PM
I do. smile
Posted By: Tomao Re: $read with case sensitivity - 17/01/11 06:42 PM
If you do, then tell people what a "workaround" you've mentioned can be applied to your own example:
Code:
//echo $replace(hello,e,y,l,x,y,l)
prints
Quote:
hlxxo

Code:
//echo $replacex(hello,e,y,l,x,y,l)
prints
Quote:
hyxxo
Posted By: Sephiroth_ Re: $read with case sensitivity - 17/01/11 07:03 PM
Well enough offtopic. :P
That was a response to this:
Originally Posted By: argv0
Actually there was a need for $replacex because there was no way to use $replace when the production of one replacement matched the value of another replacement match later on in the string, ie:

Code:
//echo -a $replacex(hello,e,l,l,x) != $replace(hello,e,l,l,x)


I know what it does.
Posted By: Tomao Re: $read with case sensitivity - 17/01/11 07:15 PM
No offense, and excuse me for being off-topic. What you've said about, and I quote,
Quote:
There WAS no real need for $replacex(). (for me at least and it was added because someone requested it or Khaled thought "would be nice to have".)
it was an irresponsible statement to make.
Posted By: starbucks_mafia Re: $read with case sensitivity - 17/01/11 08:10 PM
To summarize my thoughts on the various semi-random things that have been said so far:
  • Yes, a case-sensitive search switch would be nice.
  • No, the existence of regex search doesn't change that.
  • $replace() is not an alternative to many uses of $replacex(). Intermediate substitution is often simply not practical.


Just maybe this thread can kinda stay on topic from here onwards.
Posted By: Riamus2 Re: $read with case sensitivity - 17/01/11 08:28 PM
Intermediate replacements using $replace() aren't really valid unless you know the input. It's fine to say $replace(hello,e,y,l,x,y,l) when you know the word is hello. Because you know that you can use y without complication because it's not in the word, intermediate replacement is a way to do the same thing that $replacex() does. However, if the word or phrase is unknown, you can't do this.

If $1 is hello, then this is true:

$replace($1,e,y,l,x,y,l) = $replacex($1,e,l,l,x)

However, if $1 is yes, then it is not true (the "y" will be different from one to the next).

You can use intermediary replacement using characters that are not expected within the unknown text and often that can work, but anytime you do not know 100% what the text will be, intermediary replacement is hit or miss. That is why $replacex() is very much needed.
Posted By: Sephiroth_ Re: $read with case sensitivity - 18/01/11 03:58 PM
IT WAS AN EXAMPLE, goddamn... xD
Posted By: hixxy Re: $read with case sensitivity - 18/01/11 06:38 PM
Originally Posted By: argv0
I'm a little confused.. what's wrong with just using the regex switch? it seems to me like the conversion between wildcard and regex is trivial enough that it shouldn't really matter. IMO if there's already a reasonable way to achieve case sensitive searching that *works*, there's no real need to add another.

FWIW: a wildcard "*" becomes ".*", "?" becomes ".?" and "&" becomes "\S+" when translating to regex.


"?" would actually be "^.$" when used on its own, and ".", "^." or ".$" (depending on the position of the wildcard being middle, beginning or end of the string respectively) when used with other text to match. See for yourself:

Code:
alias test {
  echo -a $iif(? iswm $null,yes,no) ~ $regex($null,/^.?$/)
  echo -a $iif(?a iswm a,yes,no) ~ $regex(a,/^.?a$/)
  echo -a $iif(?a iswm ba,yes,no) ~ $regex(ba,/^.?a$/)
  echo -a $iif(a? iswm ab,yes,no) ~ $regex(ab,/^a.?$/)
  echo -a $iif(a? iswm a,yes,no) ~ $regex(a,/^a.?$/)
}


As you can see, the wildcard ? does not always match where .? does.

Also, regex is fairly complex. It's almost like a small sub-language which you have to learn. A lot of people looking for basic string manipulation or comparison tools will not want to learn to use regex for simple tasks like this. Regex should be used for advanced string comparison and manipulation like it was intended.

Something as simple as a case-sensitive $read() flag really shouldn't get this much opposition imo, if only for consistency with other identifiers which support case-sensitivity. Seems like a good idea to me!
Posted By: Riamus2 Re: $read with case sensitivity - 18/01/11 10:08 PM
Originally Posted By: Sephiroth_
IT WAS AN EXAMPLE, goddamn... xD


Examples are fine. When they are valid. The point is that $replace() cannot do everything that $replacex() does without potential inaccuracies. So your statement that $replacex() was not needed is false and that needs to be clear both for you and anyone reading this.
Posted By: jaytea Re: $read with case sensitivity - 19/01/11 06:15 AM
i would also like to see W and R options that behave as they do with $hfind() :P

also, here's a small snippet i had lying around that accurately generates a regular expression (which isn't always efficient!) from a wildmatch:

Code:
alias wmcs2re return $+(/(*UTF8)^\Q, $regsubex($replacecs($1, \E, \E\\E\Q, *, \E.*\Q, ?, \E.\Q), /&(?= |$)/g, \E[^ ]+\Q), \E$/s)


$wmcs2re(a ? b & *c*) = /(*UTF8)^\Qa \E.\Q b \E[^ ]+\Q \E.*\Qc\E.*\Q\E$/s

hopefully it covers all bases. argv's method of escaping meta-characters generally yields shorter and more readable expressions, but i probably made it the above way to avoid having to list them all ;D
Posted By: FroggieDaFrog Re: $read with case sensitivity - 19/01/11 01:02 PM
Here's mine though a little more complicated
Code:
$Wc2Re(wildcard text) -> Converts a wildcard matching pattern to a regular expressions
$Wc2Re(wildcard text).cs -> THe return regular expression is case sensitive

alias Wc2Re return $+(/(*UTF8)^,$regsubex($1-,/([\Q$^|[]{}()\/.+\E])|(&(?= |$))|([?*]+)/g,$Wc2Re:Rep(\t)),$,/s,$iif($prop != cs,i))

alias -l Wc2Re:Rep {
  if ($1 == &) return \S+\b
  if (* !isin $1 && ? !isin $1) return \ $+ $1
  if (? !isin $1) return .* 
  if ($count($1,?) < 5) return $str(.,$v1) $+ $iif(* isin $1,+)
  return $+(.,$chr(123),$count($1,?),$iif(* isin $1,$chr(44)),$chr(125))
}

$wc2re(a* t?est o? w?*?s has occ?????????) = /(*UTF8)^a.* t.est o. w..+s has occ.{9}$/si

edited to shorten code, and fix typing errors
© mIRC Discussion Forums