DW1 Posted October 30, 2008 Share Posted October 30, 2008 Hi,I am trying to find a regular expression that will allow me to limit a string to 10 characters. I know there are other ways to do this besides regex, but I am looking for a regex solution.Thanks AutoIt3 Online Help Link to comment Share on other sites More sharing options...
ProgAndy Posted October 30, 2008 Share Posted October 30, 2008 StringRegExp($String,"\A.{0,10}\Z") *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
DW1 Posted October 30, 2008 Author Share Posted October 30, 2008 That will test for 10 chars, but not limit it to ten chars. I am looking for a way to use StringRegExpReplace to force it to ten chars. Thank you for your help how could I make this limit to 10 chars? $string = "this1is2a3long4string" $pattern = '???' $regex = StringRegExpReplace( $string, $pattern, '' ) MsgBox(0, "test - string limited to 10 chars", $regex ) AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 30, 2008 Moderators Share Posted October 30, 2008 (edited) StringRegExpReplace($s_string, "(.{0,10})(.*?)\z", "\1")Edit:Added end of string expression Edited October 30, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
DW1 Posted October 30, 2008 Author Share Posted October 30, 2008 Thank you, works perfect, but what does "\1" do? AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 30, 2008 Share Posted October 30, 2008 Thank you, works perfect, but what does "\1" do?Everything in () is returned as a "hit".\1 is the reference to the hit 1.\1 = (.{0,10})\2 would be (.*?)\zMega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
DW1 Posted October 30, 2008 Author Share Posted October 30, 2008 Thanks a lot to both of you, SmOke and Xeno!!! AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 30, 2008 Moderators Share Posted October 30, 2008 Just FYI, StringLeft($s_string, 10) would have done the same thing. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 30, 2008 Share Posted October 30, 2008 Would it perhaps be more efficient to make the second group a non-capturing group? Link to comment Share on other sites More sharing options...
DW1 Posted October 30, 2008 Author Share Posted October 30, 2008 Just FYI, StringLeft($s_string, 10) would have done the same thing.It was actually not an autoit question but rather regex in general. I have a small regex utility that I use in batch file and I was having issues with the syntax.I know there are a bunch of regex gurus (you, progandy, xeno, etc. ) on these forums, so I figured I would ask here. After all, the autoit forums are my fav Would it perhaps be more efficient to make the second group a non-capturing group?How can you make it a non-capturing group? AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 30, 2008 Moderators Share Posted October 30, 2008 It was actually not an autoit question but rather regex in general. I have a small regex utility that I use in batch file and I was having issues with the syntax.I know there are a bunch of regex gurus (you, progandy, xeno, etc. ) on these forums, so I figured I would ask here. After all, the autoit forums are my fav How can you make it a non-capturing group?Be careful using our regex's with other types. Remember we use the PCRE engine others may or may not.http://www.regular-expressions.info/tutorial.htmlIn the help file shows the expression for non-capturing. (?: ... ) Non-capturing group. Behaves just like a normal group, but does not record the matching characters in the array nor can the matched text be used for back-referencing. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
DW1 Posted October 30, 2008 Author Share Posted October 30, 2008 Good to know SmOke_N, thanks. I am unsure what engine the exe that I am calling is using, but it did work correctly with the only modification being: Instead of using "\1" I have to use "$1". Thanks again AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now