Jump to content
Sign in to follow this  
DW1

RegEx help

Recommended Posts

DW1

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

Share this post


Link to post
Share on other sites
ProgAndy

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

Share this post


Link to post
Share on other sites
DW1

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 )

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
Xenobiologist

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

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
Richard Robertson

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

Share this post


Link to post
Share on other sites
DW1

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?

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
DW1

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

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.