PDA

View Full Version : WTF is this?


willofgod
29-11-2005, 08:51 AM
I've got a web developer extension to Firefox, and accidently clicked the View Source button in a computershopper article and heres *some* of what I got back (looks like a chant or something from the bible in coded form!):

1:1 Ere-thay as-way a-ay an-may in-ay e-thay and-lay of-ay Uz-ay,
ose-whay ame-nay as-way Ob-jay; and-ay at-thay an-may as-way
erfect-pay and-ay upright-ay, and-ay one-ay at-thay eared-fay Od-
gay, and-ay eschewed-ay evil-ay.
1:2 And-ay ere-thay ere-way orn-bay unto-ay im-hay even-say
ons-say and-ay ee-thray aughters-day.
1:3 Is-hay ubstance-say also-ay as-way even-say ousand-thay eep-
shay, and-ay ee-thray ousand-thay amels-cay, and-ay ive-fay
undred-hay oke-yay of-ay oxen-ay, and-ay ive-fay undred-hay e-shay
asses-ay, and-ay a-ay ery-vay eat-gray ousehold-hay; o-say at-thay
is-thay an-may as-way e-thay eatest-gray of-ay all-ay e-thay en-
may of-ay e-thay east-ay. -->

imported_mrcol
29-11-2005, 11:37 AM
looks like something ya give to a student to practice working with strings and regular expresssions.

disregard all "ay" at the end.

if there is a - be4 the ay part... take everthing be4 the "ay" and put it be4 the part that begins "-"... eg an-may = man, e-thay = the,
e-thay = of, e-thay

so

1.1 There was a man in the land of Uz whose name was jOb; and that feared gOd, and that man was perfect and upright, and one thatfeared gOd, eschewed evil.

1.2 And there were born unto him seven sons and three daughters.

1.3 hIs substance also was seven thousand sheep, and three thousand camels, and five hundred yoke of oxen, and five hundred she asses, and a very great household; sothat this man was the greatest of all the men of the east.


simple.

willofgod
29-11-2005, 11:54 AM
Good effort!

I've tried to teach myself regular expressions for use in my vb scripts. I've had a lot of success, but I dont pretend to have done anything more than scratch the surface. I find em nightmarishly vexing like the programming equivalent of a puzzel! I still cant use them without the aid of a reference manual either.

But very powerful!

imported_mrcol
29-11-2005, 12:15 PM
regular expressions cant be difficult and unless you work with them every day you aint going to remember how to do anything with them.

However, you could sort that out without an regular expression. Perl would probably offer the best inbuilt functions for sorting it out, php also very easy.... not a clue about VB, JAVA and other such languages. Could probably solve it in 20LOC or so in most languages with no error handling.

r1ncewind
29-11-2005, 03:10 PM
WTF are you two going on about?!? :?

BuLLiTT
29-11-2005, 05:16 PM
:? mmm....beats me too. i take it its the language you use for building scripts within a computer program as in 'c', 'c+' etc. etc. am i going in the right direction Col?
My dad uses 'c' to formulate mathematical algorithms to predict the positions of stellar objects down to about 6 decimal places then compares them to actual observed positions to find out if he was correct. thats his past-time! 8O

The_Joker
29-11-2005, 05:25 PM
your dad needs to stay IN a little more then :p

Benny
29-11-2005, 06:19 PM
Its enough to drive a person to drink, where's me aldi lager gone, a few cans of this and it'll all make sense.

imported_mrcol
29-11-2005, 07:51 PM
regular expressions are like a language within a language and can do some fucked up stuff on strings (group text and numbers, like a sentence, paragragh etc etc)

anyways, i wont try to explain...I have lifted this [Only registered and activated users can see links] and this is covering the basics. They can get real complicated real quick when you get down to the imtermediate stuff, forget the advanced stuff.... but basically without them you could be writting masses of code for search and replace.

Regular Expression Basics
Regular expressions are made up of normal characters and metacharacters. Normal characters include upper and lower case letters and digits. The metacharacters have special meanings and are described in detail below.

In the simplest case, a regular expression looks like a standard search string. For example, the regular expression "testing" contains no metacharacters. It will match "testing" and "123testing" but it will not match "Testing".

To really make good use of regular expressions it is critical to understand metacharacters. The table below lists metacharacters and a short explanation of their meaning.

Metacharacter Description

.
Matches any single character. For example the regular expression r.t would match the strings rat, rut, r t, but not root.
$
Matches the end of a line. For example, the regular expression weasel$ would match the end of the string "He's a weasel" but not the string "They are a bunch of weasels."
^
Matches the beginning of a line. For example, the regular expression ^When in would match the beginning of the string "When in the course of human events" but would not match "What and When in the" .
*
Matches zero or more occurences of the character immediately preceding. For example, the regular expression .* means match any number of any characters.
\
This is the quoting character, use it to treat the following character as an ordinary character. For example, \$ is used to match the dollar sign character ($) rather than the end of a line. Similarly, the expression \. is used to match the period character rather than any single character.
[ ]
[c1-c2]
[^c1-c2]
Matches any one of the characters between the brackets. For example, the regular expression r[aou]t matches rat, rot, and rut, but not ret. Ranges of characters can specified by using a hyphen. For example, the regular expression [0-9] means match any digit. Multiple ranges can be specified as well. The regular expression [A-Za-z] means match any upper or lower case letter. To match any character except those in the range, the complement range, use the caret as the first character after the opening bracket. For example, the expression [^269A-Z] will match any characters except 2, 6, 9, and upper case letters.
\< \>
Matches the beginning (\<) or end (\>) or a word. For example, \<the matches on "the" in the string "for the wise" but does not match "the" in "otherwise". NOTE: this metacharacter is not supported by all applications.
\( \)
Treat the expression between \( and \) as a group. Also, saves the characters matched by the expression into temporary holding areas. Up to nine pattern matches can be saved in a single regular expression. They can be referenced as \1 through \9.
|
Or two conditions together. For example (him|her) matches the line "it belongs to him" and matches the line "it belongs to her" but does not match the line "it belongs to them." NOTE: this metacharacter is not supported by all applications.
+
Matches one or more occurences of the character or regular expression immediately preceding. For example, the regular expression 9+ matches 9, 99, 999. NOTE: this metacharacter is not supported by all applications.
?
Matches 0 or 1 occurence of the character or regular expression immediately preceding.NOTE: this metacharacter is not supported by all applications.
\{i\}
\{i,j\}
Match a specific number of instances or instances within a range of the preceding character. For example, the expression A[0-9]\{3\} will match "A" followed by exactly 3 digits. That is, it will match A123 but not A1234. The expression [0-9]\{4,6\} any sequence of 4, 5, or 6 digits. NOTE: this metacharacter is not supported by all applications.

-----
check the link i pulled it from for more information.

A lot of powerfull text editors have regular expression functions built into it, wouldnt say they are worth learning outright unless you are working on strings day in day out... o'reilly do a pocket book reference, only about a tenner and worth it's weight in gold :)

r1ncewind
29-11-2005, 11:48 PM
right col, crank it down about 10 notches and im with you mate. 8O
if theres not a little green light that tells me when my computer is off im fooked.

it used to be so much simpler when you could programme stuff on the old spectrums. :(

willofgod
30-11-2005, 03:43 PM
Heres an example of a real Regular Expression which I setup when I was trying to teach myself how to use them.

Copy the script in red into Notepad (make sure wrapping is off) and save it on your desktop as test.vbs and double click it. At the prompt type in [Only registered and activated users can see links] or something.

The script pings the server you type in. However it obviously doesn't know what the IP address is for the server you typed in is, so it cant search for it in the output directly. This is were the Regular Expression comes into play. The regular expression basically searches for anything that looks like an IP address using a pattern. The following RegEx pattern will find an IP address in a string:

([0-9]{1,3}\.){3}[0-9]{1,3}

That pattern took me hours to figure out. But looking at it now (and I'm sure Col will agree), it looks like it was written by a two year old compared to what regular expressions can do! Its hard to get your head around, but is incredibly powerful.

Option Explicit

'Declare vaiables
Dim shell
Dim exec

'Create objects
Set shell = createObject("WScript.Shell")
Set exec = shell.exec("ping " & InputBox("Enter a server or domain name"))

'Get IP address
Wscript.Echo getIPAddress(exec.stdOut.readAll())

'Destroy objects
Set exec = Nothing
Set shell = Nothing

'--------------------------------------+
' SUBS/FUNCTIONS
'--------------------------------------+

Function getIPAddress(inputString)

'Declare variables
Dim re
Dim oMatches

'Setup Regular Expression object
Set re = New RegExp

'Set RegEx attributes
re.Pattern = "([0-9]{1,3}\.){3}[0-9]{1,3}"
re.global = False

'Get Result
Set oMatches = re.Execute(inputString)

'Determine result
Select Case True
Case oMatches.Count = 0
getIPAddress = "Nothing returned for your server/domain name!"
Case oMatches.Count > 0
getIPAddress = "IP address for your server is: " & oMatches(0)
Case Else
getIPAddress = "Something odd happened... " & vbcr & vbcr & "yes this is another meaningless message!"
End Select

'Destroy objects and variables
Set oMatches = Nothing
Set re = Nothing

End Function

imported_mrcol
30-11-2005, 11:49 PM
that VB... must be, it looks horrible.... check out C#, tis a lot nicer... I'd describe it as a hybrid of C++ and JAVA with a pinch of VB thrown in for good measure. It's still a bit of a RAD language, but more of a grown up one :)

shifty
01-12-2005, 03:46 PM
Christ Col & Willo,sounds like that language called Gobaldy Gook,did`nt know you both could speak it 8O .
Now where did I put that translation book.

Hey and Rince I`m with you mate,doing it on a Speccy,... oh those were the days :D :D .
One mistake after typing it all in ,and it would all go tit`s up 8O .
Great fun though.

Col ,what on earth is Rad language :?: :?: :?: ,does that enable you to talk to radiators,and get an answer back. :D .

This is too deep for me,I`ve only just got by me ABC 8O 8O :D .

BuLLiTT
05-12-2005, 06:09 PM
8) Col? my dad is having trouble with using c at the mo. he's using c on windows 95 on an old AMD 500, and is worried incase his machine goes tits up (it is about 10 yrs old!). trouble is as he's getting on he dreads using a more modern windows as A; the program is not compatible with modern windows and B; he's to old to learn another system. is there a 'crossover' program that would let him use his program on a new platform ie. XP? cheers Col :wink:
btw he works to 8 decimal places if thats any help

willofgod
05-12-2005, 06:20 PM
He should be able to run his program on XP using compatability mode for whatever program he's using. Have a look at this article, it explains everything you need to know:

[Only registered and activated users can see links]