Jump to content

Recommended Posts

Posted

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

Posted

StringRegExp($String,"\A.{0,10}\Z") :mellow:

*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

Posted

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 :mellow:

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 )
  • Moderators
Posted (edited)

StringRegExpReplace($s_string, "(.{0,10})(.*?)\z", "\1")

Edit:

Added end of string expression

Edited 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.

Posted

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 (.*?)\z

Mega

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

  • Moderators
Posted

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.

Posted

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 :mellow:

Would it perhaps be more efficient to make the second group a non-capturing group?

How can you make it a non-capturing group?
  • Moderators
Posted

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 :mellow:

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.html

In 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.

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...