mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
$read with case sensitivity #228937 16/01/11 06:41 AM
Joined: Oct 2003
Posts: 214
S
Sephiroth_ Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 214
Almost every thingy has it so far.

Would be very handy together with wildmask search.


one step closer to world domination
Re: $read with case sensitivity [Re: Sephiroth_] #228938 16/01/11 07:18 AM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
You could use the r switch for a case-sensitive regex match.
That of course does mean you need to escape certain characters.

Re: $read with case sensitivity [Re: 5618] #228939 16/01/11 08:40 AM
Joined: Oct 2003
Posts: 214
S
Sephiroth_ Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 214
I know, i'm doing this right now.

Its just a feature request.


one step closer to world domination
Re: $read with case sensitivity [Re: Sephiroth_] #228945 16/01/11 11:50 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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.

Re: $read with case sensitivity [Re: Tomao] #228946 17/01/11 12:31 AM
Joined: Jul 2006
Posts: 3,738
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,738
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


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $read with case sensitivity [Re: Wims] #228947 17/01/11 01:52 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Thanks for connecting the dots, Mr. Wims. tired

Re: $read with case sensitivity [Re: Sephiroth_] #228948 17/01/11 02:22 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
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.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: $read with case sensitivity [Re: argv0] #228954 17/01/11 05:31 AM
Joined: Oct 2003
Posts: 214
S
Sephiroth_ Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 214
There was also no real need for $replacex() and it was added. It just makes things easier thats all.


one step closer to world domination
Re: $read with case sensitivity [Re: Sephiroth_] #228955 17/01/11 09:41 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
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.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: $read with case sensitivity [Re: argv0] #228957 17/01/11 11:11 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Re: $read with case sensitivity [Re: argv0] #228959 17/01/11 12:04 PM
Joined: Oct 2003
Posts: 214
S
Sephiroth_ Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 214
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.


one step closer to world domination
Re: $read with case sensitivity [Re: Sephiroth_] #228968 17/01/11 06:11 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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

Re: $read with case sensitivity [Re: Tomao] #228970 17/01/11 06:35 PM
Joined: Oct 2003
Posts: 214
S
Sephiroth_ Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 214
I do. smile


one step closer to world domination
Re: $read with case sensitivity [Re: Sephiroth_] #228971 17/01/11 06:42 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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

Re: $read with case sensitivity [Re: Tomao] #228973 17/01/11 07:03 PM
Joined: Oct 2003
Posts: 214
S
Sephiroth_ Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 214
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.


one step closer to world domination
Re: $read with case sensitivity [Re: Sephiroth_] #228974 17/01/11 07:15 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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.

Re: $read with case sensitivity [Re: Sephiroth_] #228975 17/01/11 08:10 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: $read with case sensitivity [Re: Sephiroth_] #228976 17/01/11 08:28 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Re: $read with case sensitivity [Re: Riamus2] #228992 18/01/11 03:58 PM
Joined: Oct 2003
Posts: 214
S
Sephiroth_ Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 214
IT WAS AN EXAMPLE, goddamn... xD


one step closer to world domination
Re: $read with case sensitivity [Re: argv0] #228995 18/01/11 06:38 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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!

Page 1 of 2 1 2