mIRC Home    About    Download    Register    News    Help

Print Thread
#152912 08/07/06 03:05 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
hey guys,a little stuck with regex code and thought id come seek some advice,first 1 is:
Code:
var %t = /^\[\d{2}:\d{2}:\d{2}p EST\]$/S
var %t2 = /^\[\d{2}:\d{2}:\d{2}a EST\]$/S
  if (!$regex($1-,%t) && !$regex($1-,t2))

would the following code match,as an example:

[08:47:17a EST] and [03:42:17p EST]

as an exact match on the format (not the numbers them selves)and if so,
how would i write the var so it will all be in 1 line,
would this work?
Code:
var %t = /^\[\d{2}:\d{2}:\d{2}\(.+\) EST\]$/S
  if (!$regex($1-,%t))

iv tried a couple ways but it seems to kill words like best , destination etc so this is why i need it to be an exact match and only block the examples.

Second part of this post is,when using special characters like « and »,example:
«(Jim)» «(Ben)» «(Freddie)» «(Mike)»

does the » have to be escaped at all or anything special on the way it has to be writing or would the following code pick up on the above
Code:
var %n = /^\«\(?:Jim|Ben|Freddie|Mike\)»$/S
  if ($regex($1-,%n))


if you need anymore info plz ask away,TIA to anyone that can help smile

#152913 08/07/06 04:32 PM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Quote:
hey guys,a little stuck with regex code and thought id come seek some advice,first 1 is:
Code:
var %t = /^\[\d{2}:\d{2}:\d{2}p EST\]$/S
var %t2 = /^\[\d{2}:\d{2}:\d{2}a EST\]$/S
  if (!$regex($1-,%t) && !$regex($1-,t2))

would the following code match,as an example:

[08:47:17a EST] and [03:42:17p EST]


No, for a few reasons.

1. You're missing a % in !$regex($1-,t2)
2. You're using ! which means it will match anything that does NOT follow either format.
3. You specified $1- and also imply an exact match. Logic leads me to believe the line you're comparing against the pattern probably contains other text (I don't know anyone that would outright send "[12:34:56a EST]" as a chat message to a channel :tongue:), and thus your pattern is never going to match.

Quote:
Second part of this post is,when using special characters like « and »,example:
«(Jim)» «(Ben)» «(Freddie)» «(Mike)»

does the » have to be escaped at all or anything special on the way it has to be writing or would the following code pick up on the above
Code:
var %n = /^\«\(?:Jim|Ben|Freddie|Mike\)»$/S
  if ($regex($1-,%n))


« and » don't need to be escaped. And again you'd possibly have the same problem here that I mentioned above (See 3).

#152914 08/07/06 05:29 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
thanks for the reply schaefer31,sorry %t2 was a typo on my part when posting the thread.

Quote:

2. You're using ! which means it will match anything that does NOT follow either format.


ah ok my bad, you did a script for me HERE and from your pm explaing the script,it says it wont return any thing in the list
Quote:

if (!$regex($4,%noshow) && !$regex($2,%noshow)) {

The ! prefix means to match anything except those in the list.

maybe iv miss understood your explaintion?

Quote:

3. You specified $1- and also imply an exact match. Logic leads me to believe the line you're comparing against the pattern probably contains other text (I don't know anyone that would outright send "[12:34:56a EST]" as a chat message to a channel ), and thus your pattern is never going to match.


yep yep its almost at the end of the line of txt,there is a few more words before it gets to [12:34:56a EST](its never in the same place in the line of txt but always present).

I thought as its the only thing that is always present,I could get regex to lock onto it and stop it from showing up,maybe i miss understand your explainations or am i just way off base :tongue: ?

I'v done pretty well with changing it and adding things to it etc (with a few snags that this board was able to help with) but maybe I have just been lucky grin.
thanks again for the reply schaefer i'll keep at it wink

/me goes back to read some more

#152915 08/07/06 07:03 PM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Try

Code:
...
if ($regex($1-,/\[(?:[0-1]?\d|2[0-4])(?::[0-5]\d){2}(?:a|p) EST\]/)) {
  ; execute commands if the pattern matched
}
...


It will match if a valid timestamp is anywhere in a message. By valid, it means the time has to be valid (e.g. 25:22:67 is not valid).

It will also match single or double digit for the hours (e.g. 1:23:59 and 01:23:59)

Edit: Corrected parenthesis mismatch :tongue:

#152916 08/07/06 09:02 PM
Joined: Oct 2005
Posts: 71
D
D00M Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Oct 2005
Posts: 71
Thanks once again schaefer for the reply,I tried adding the code above to the script I have but it seemed to error in mirc no matter what line I move it too(prolly just me adding it in wrong place etc).

None the less with some playing with the filter line I have already in the code I managed to get it to lock onto the "a EST" and p EST" part of [11:07:52p EST] and not block words like best,desttination etc.. smile


Link Copied to Clipboard