Normal Topic RegEx Replacement (Read 834 times)
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
RegEx Replacement
Apr 21st, 2012 at 5:11pm
Print Post Print Post  
Looking in a string for specific leading four characters (like "AZTL" or "BYML" or "CXGR" only at beginning of the string).
Want to remove the second and fourth character.
Here is the code
Code
Select All
var vNewString as String
var vLookin as String
var vFind as String
var vUse as String

vLookin = "AZTLCDEFG"
vFind = "^[(A)(Z)(T)(L)|(B)(Y)(M)(L)|(C)(X)(G)(R)](.*)"
vUse = "$1$3$5"
vNewString = @RegexReplaceString(vLookIn,vFind,vUse,0)
WriteLn(vNewString)
 



vNewString should be "ATCDEFG" but it is $1$3$5 instead.

I have tried different variations of vFind without success, but this one seems to be closest to what I think it should look like.  Can you see the error(s) and help with a modification?

The specific Find strings will be dynamically changing, and may not always be the 2nd/4th chars that are dropped, so
I don't think it lends itself to a bunch of IF strings.  I think it needs to use RegEx type of replacement of string patterns.  That will allow me to just redefine the two variables, vFind and vUse.

--------------

Question about Sesame's flavor of RegEx:  I know there are some different flavors of RegEx.  Which flavor of RegEx is closest to SBasic:
JGsoft/.NET/Java/Perl/ECMA/Python/Ruby/Tcl/PHP ereg/PHP preg/REAL basic/Oracle/Post gres/XPath/R
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: RegEx Replacement
Reply #1 - Apr 22nd, 2012 at 12:53am
Print Post Print Post  
As has been mentioned before, it is simple replacement and does not support substitution. While regex libraries often have substitution as a result parameter, the end application performs the actual replacement in the source string. Should we see a dramatic upsurge in demand among our users for more complex regex functions, I'd be happy to implement them. So far, the small number using regex, use it largely to parse XML. Sesame3 has a much more extensive and capable XML library, so even that use should be obsolete in the next major release.

There are essentially two modern implementations of regex: posix and perl. All of the applications you mention use (or implement a subset of) one or the other or both of these. Sesame uses the library prepared for perl with posix extensions. Of course, this only refers to the available syntax. Much of the library is unexposed and well out of the scope of Sesame. If you want to dive in the deep end, I suggest finding a Windows version of "sed" and use SBasic's redirect process command.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: RegEx Replacement
Reply #2 - Apr 22nd, 2012 at 2:02am
Print Post Print Post  
The correct answer was supposed to be something like "you have to many parentheses" or a similar problem!  This is not what I wanted to hear, a syntax error was much preferred.

Thanks for the info.  So I will try to take your suggestion to find a windows command line RegEx tool so I can pass the variables out and parse the return.

  
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: RegEx Replacement
Reply #3 - Apr 22nd, 2012 at 4:53pm
Print Post Print Post  
Hi Mark.  I am one of the users who would love to see more conventional RegEx tools.  I think that many people are just ignorant about what can be done with it.

But in the meantime, for obfusc88, try using RxFind, a command line utility for RegEx expressions.  It was free and could be downloaded from http://rxfind.codeplex.com/. ; No manual as of a few years ago, only the command line HELP command.

I had used it with other some batch files a few years ago, but have not tried it out with Sesame yet, think I may try that out, thanks for the idea Mark.
  



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