Normal Topic Besides Easter... (Read 1110 times)
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Besides Easter...
Apr 16th, 2006 at 9:43pm
Print Post Print Post  
I spent the day writing two new commands:

@RegexFindString(regular_expression as string, str as string) as string - this one finds the every instance of the "regular_expression" in "str" and returns the starting points and lengths as a elements in a string array.

So:
Code
Select All
str2 = @RegexFindString("mark", "he is mark, and mark is his name")
 



produces "7;4;17;4" - because "mark" starts at the seventh character and is 4 chars long, and the other "mark starts at the seventeenth character and is also 4 chars long.

The other command is @RegexBetweenString(reg1 as string, reg2 as string, str as string) as string, that returns the string between two regular expressions (reg1 and reg2) in the string "str".

Code
Select All
aa = @RegexBetweenString("\<TD\>", "\<\/TD\>", "<TD>Producer: Steven Speilberg</TD>")
 



will return: "Producer: Steven Speilberg"

I used an HTML example, because I envision that the second of these commands, in particular, might be used with HTTPGetHTML and HTTPPostHTML to build applications that can gather information from web sites. For example, you could build an app where the user enters a movie title. The application can then use HTTPGetHTML to query www.imdb.com (the Internet Movie Database) and then uses @RegexBetweenStrings to parse out all of the credits, movie posters, and whatnot for your application.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Besides Easter...
Reply #1 - Apr 17th, 2006 at 8:15pm
Print Post Print Post  
Looking at these with great interest Mark.

Before the Regex functions are released, do you think that you could provide some consistency in the sequence for the parameters?  Suggest using @RegexFunction(Source to search,Regex1, Regex2, Result) or something similar?  The consistency should help to memorize the sequence. 

I don't recall the specifics at the moment, but if you review the functions you have listed, I think you will see what I am talking about.  Or...I may also be wrong, you may have already done that....

Thanks again for the tools..... I think that these latest ones many help me to do some of the Replace functions that I asked about in another thread.

I have never seen a Regex that returned positions like MidStr, that is quite inventive ..... keep up the new tools.

Thanks again.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Besides Easter...
Reply #2 - Apr 17th, 2006 at 8:22pm
Print Post Print Post  
Quote:
Looking at these with great interest Mark.

Before the Regex functions are released, do you think that you could provide some consistency in the sequence for the parameters?  Suggest using @RegexFunction(Source to search,Regex1, Regex2, Result) or something similar?  The consistency should help to memorize the sequence. 



They are consistent. The first argument or set of arguments is always the regular expression(s), then the string to be search, and lastly the replacement string (if there is one). There is never a result passed as an argument, only returned.

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Besides Easter...
Reply #3 - Apr 17th, 2006 at 9:58pm
Print Post Print Post  
Quote:
They are consistent. The first argument or set of arguments is always the regular expression(s), then the string to be search, and lastly the replacement string (if there is one).
Maybe we are looking at different things.  Here are the three most recent Regex commands that I saw:

1.  @RegexFindString(regular_expression as string, str as string)
2.  @RegexBetweenString(reg1 as string, reg2 as string, str as string)
3.  @RegexReplaceString(expression as string, str as string, replacement as string)[

I read those as:
1.  exp1 / sourcestring
2.  exp1 / exp2 / sourcestring
3.  exp1 / sourcestring / exp2
This appears to be inconsistent to me.  Maybe it's just the newness of the commands here.

Normal @Replace uses sourcestring / exp1 / exp2,   It would be good to have same format, with sourcestring first.  Most other functions also have sourcestring as first parameter, like @Replace, @ReplaceFir, @ReplaceLas, @Left/Right/MidStr, @Delete, etc.

Again, just a suggestion, figured still time to change it now.  What is more important than the syntax consistency though is the actucal functions.  Thanks again.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Besides Easter...
Reply #4 - Apr 17th, 2006 at 11:15pm
Print Post Print Post  
Quote:
Maybe we are looking at different things.  Here are the three most recent Regex commands that I saw:

1.  @RegexFindString(regular_expression as string, str as string)
2.  @RegexBetweenString(reg1 as string, reg2 as string, str as string)
3.  @RegexReplaceString(expression as string, str as string, replacement as string)[

I read those as:
1.  exp1 / sourcestring
2.  exp1 / exp2 / sourcestring
3.  exp1 / sourcestring / exp2
This appears to be inconsistent to me.  Maybe it's just the newness of the commands here.



3. The third argument to @RegexReplaceString is not a regular expression, just an ordinary string.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Besides Easter...
Reply #5 - Apr 18th, 2006 at 6:45pm
Print Post Print Post  
You talked me into it:

The regex functions now take the source (the string to be searched) as the first argument:

@RegexBetweenStrings(source as string, exp1 as string, exp2 as string) as string

@RegexFindString(source as string, exp as string) as string

@RegexReplaceString(source as string, exp as string, replacement as string) as string

That way they are consistent between each and the various Q&A replace functions.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Besides Easter...
Reply #6 - Apr 18th, 2006 at 10:05pm
Print Post Print Post  
You really are too good Mark.  Roll Eyes

The more you give, the more we will ask for.

Thanks again   Grin   Grin
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged