jugador Posted May 29, 2019 Share Posted May 29, 2019 Local $Input = "May" ;word length is 3 Local $Output = StringRegExpReplace($Input, '\w{3}', "June") ;it’s work But if length of word is unknown, for my example length of word anything above 2. then how to write it...... Link to comment Share on other sites More sharing options...
mikell Posted May 29, 2019 Share Posted May 29, 2019 (edited) 32 minutes ago, jugador said: length of word anything above 2 Suggestion : \w{2,} which means : 2 or more word chars, greedy BTW the help file is your best friend Edited May 29, 2019 by mikell jugador 1 Link to comment Share on other sites More sharing options...
jugador Posted May 29, 2019 Author Share Posted May 29, 2019 (edited) mikell thanks 😅 any example on {x,}+ and {x,}? Edited May 29, 2019 by jugador Link to comment Share on other sites More sharing options...
jchd Posted May 30, 2019 Share Posted May 30, 2019 The block of text just above the table you mention explains it all. At least I've tried to make it as "simple" and understandable as possible, but as the inherent working of regex isn't the paradigm most users are used to in their daily programming language(s) it may need some chewing to swallow. Greedy means that a repeated pattern will match the maximum subject input which doesn't cause the rest of the pattern to fail. That may need backtracking. Lazy means that a repeated pattern will match the minimum subject input which doesn't cause the rest of the pattern to fail. That may need backtracking. Possessive means that a repeated pattern will match the maximum subject input, but without ever backtracking backwards inside the "possessed" part. This may cause the rest of the pattern to fail. _ArrayDisplay(StringRegExp("AbABAbabbbabaaabbAbAb", "(?i)([ab]+)(aba)(.*)", 1), "Greedy") _ArrayDisplay(StringRegExp("AbABAbabbbabaaabbAbAb", "(?i)([ab]+?)(aba)(.*)", 1), "Lazy") _ArrayDisplay(StringRegExp("AbABAbabbbabaaabbAbAb", "(?i)([ab]++)(aba)(.*)", 1), "Possessive") I used uppercase to help you identify which substring was captured. In the possessive case, the subpattern [ab]++ will match the whole subject, but the rest of the pattern is left with nothing to match, hence failing flat on its nose. In general, the possessive qualifier or its father the atomic grouping (see help) is unavoidable when an unlimited subpattern is enclosed inside another unlimited subpattern and there are instances where no match is possible. In such case the huge number of nested backtrackings required makes the regex extremely slow. Consider this case where we're after an unbounded repeat of "words" (strings of letters) or integers. Subjects which match this pattern will match very fast, but when they don't, the regex will have to try many (really many) nested split points in the subject before failing. Local $s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", $t $t = TimerInit() For $i = 1 To 100 StringRegExp($s, "(\w*|[-\d]*)*[xy]") Next ConsoleWrite("Without possessive qualifier: " & StringFormat("%7.4f\n", TimerDiff($t) / 1000)) $t = TimerInit() For $i = 1 To 100 StringRegExp($s, "(\w*+|[-\d]*)*[xy]") Next ConsoleWrite("With possessive qualifier : " & StringFormat("%7.4f\n", TimerDiff($t) / 1000)) jugador 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
mikell Posted May 30, 2019 Share Posted May 30, 2019 Nice tutorial to ease understanding of possessive quantifiers - though the few lines in the help file were explicit enough IMHO BTW I personally appreciate the naming "docile" used on rexegg for usual greedy quantifiers (which allow backtracking if needed) against "possessive" ones (which do not) Link to comment Share on other sites More sharing options...
jugador Posted May 30, 2019 Author Share Posted May 30, 2019 Thanks jchd for keeping it simple... 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