Iczer Posted October 22, 2013 Share Posted October 22, 2013 Lets say? i have some regexp pattern : "(group #1)(group #2)(group #3)(group #4)(group #5)" Group #3 is something like "(d{4})" And Regexp : $result = StringRegExp($rawText, $pattern,0) How i can make pattern match only if Group #3 will capture number bigger than 1905? Less than 1812? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 22, 2013 Moderators Share Posted October 22, 2013 Iczer,I think you will have to extract the group and then do the comparison. Can you let us have an example of $rawText and $pattern so we can experiment? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted October 22, 2013 Share Posted October 22, 2013 How i can make pattern match only if Group #3 will capture number bigger than 1905? Less than 1812? Whatever sensible set x belongs to, (x > 1905) AND (x < 1812) is only satisfied for elements of the empty set... 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...
Solution mikell Posted October 23, 2013 Solution Share Posted October 23, 2013 Maybe try this, should match any number < 1905 (0?d?d?d) | (1[0-8]d{2}) | (190[0-4]) Matches (0 to 999) or (1000 to 1899) or (1900 to 1904), I suppose so Link to comment Share on other sites More sharing options...
Malkey Posted October 23, 2013 Share Posted October 23, 2013 (edited) mikell good idea - just matching characters. less than 1812 RE Pattern 0*d{1,3} | 1[0-7]d{2} | 18[0-1][0-1] matches 000-0999 or 1000-1799 or 1800-1811 greater 1905 RE Pattern [1-9]d{4,} | [2-9]d{3} | 190[6-9] | 19[1-9]d matches 10000-infinity or 2000-9999 or 1906-1909 or 1910-1999 #include <Array.au3> Local $rawText = "8 12 345 wiz 1800 zip 1900 1811 1812 1813 1904 1905 1906 2001A 2000 bang 10000" Local $sGroup1REPattern = "\b(0*\d{1,3}|1[0-7]\d{2}|18[0-1][0-1])\b" ; less than 1812 Local $aArray1 = StringRegExp($rawText, $sGroup1REPattern, 3) _ArrayDisplay($aArray1, "less than 1812") Local $sGroup2REPattern = "\b([1-9]\d{4,}|[2-9]\d{3}|190[6-9]|19[1-9]\d)\b" ; greater 1905 Local $aArray2 = StringRegExp($rawText, $sGroup2REPattern, 3) _ArrayDisplay($aArray2, "greater 1905") Local $sGroup3REPattern = "\b(0{0,}\d{1,3}|1[0-7]\d{2}|18[0-1][0-1]|[1-9]\d{4,}|[2-9]\d{3}|190[6-9]|19[1-9]\d)\b" ; less than 1812 or greater 1905 Local $aArray3 = StringRegExp($rawText, $sGroup3REPattern, 3) _ArrayDisplay($aArray3, "(x<1812 or x>1905)")Edit:- To help create the regular expression patterns to find numbers greater than or less than specified numbers, I have created functions that will do the job. Here is the example. expandcollapse popup#include <Array.au3> Local $rawText = "2 7 12 345 wiz 1800 zip 1900 1811 1812 1813 1904 1905 1906 2001A 2000 bang 10000 96 97 98" Local $iNum1 = 1812 Local $iNum2 = 1905 ; --------- Less than $iNum1 ------------------ Local $aArray1 = StringRegExp($rawText, _REPatternLessThan($iNum1), 3) ConsoleWrite("LessThan " & $iNum1 & " " & _REPatternLessThan($iNum1) & @LF) _ArrayDisplay($aArray1, "less than " & $iNum1) ; --------- Greater than $iNum2 ------------------ Local $aArray2 = StringRegExp($rawText, _REPatternGreaterThan($iNum2), 3) ConsoleWrite("GreaterThan " & $iNum2 & " " & _REPatternGreaterThan($iNum2) & @LF) _ArrayDisplay($aArray2, "greater than " & $iNum2) ; --------- Less than $iNum1 or greater than $iNum2 ----------- Local $aArray3 = StringRegExp($rawText, _REPatternLessAndGreaterThan($iNum1, $iNum2), 3) ConsoleWrite(_REPatternLessAndGreaterThan($iNum1, $iNum2) & @LF) ; _ArrayDisplay($aArray3, "(x<" & $iNum1 & " Or x>" & $iNum2 & ")") ; Creates Reg Exp Pattern which will match all numbers less than $iNumLessThan and all numbers greater than $iNumGreaterThan. Func _REPatternLessAndGreaterThan($iNumLessThan, $iNumGreaterThan) Return StringTrimRight(_REPatternLessThan($iNumLessThan), 3) & "|" & _ StringTrimLeft(_REPatternGreaterThan($iNumGreaterThan), 3) EndFunc ;==>_REPatternLessAndGreaterThan ; Creates Reg Exp Pattern which will match all numbers less than $iNum. Func _REPatternLessThan($iNum) Local $aChars = StringRegExp($iNum, ".", 3), $iLen = UBound($aChars) Local $sRetPat = "\b(" If $iLen <> 1 Then $sRetPat &= "0*\d{1," & $iLen - 1 & "}|" For $i = 0 To $iLen - 1 If ($aChars[$i] <> 0) Then $sRetPat &= StringLeft($iNum, $i) & "[0-" & $aChars[$i] - 1 & "]\d{" & ($iLen - $i - 1) & "}|" Next $sRetPat = StringRegExpReplace($sRetPat, "(\\d\{0\}|\{1\}|\|$)", "") & ")\b" ; Erase "\d[0}" and "{1}" and trailing "|". Return StringRegExpReplace($sRetPat, "\[(\d)-\1\]", "\1") ; Replace "[n-n]" with "n". EndFunc ;==>_REPatternLessThan ; Creates Reg Exp Pattern which will match all numbers greater than $iNum. Func _REPatternGreaterThan($iNum) Local $aChars = StringRegExp($iNum, ".", 3), $iLen = UBound($aChars) Local $sRetPat = "\b([1-9]\d{" & $iLen & ",}|" For $i = 0 To $iLen - 1 If $aChars[$i] <> 9 Then $sRetPat &= StringLeft($iNum, $i) & "[" & $aChars[$i] + 1 & "-9]\d{" & ($iLen - $i - 1) & "}|" Next $sRetPat = StringRegExpReplace($sRetPat, "(\\d\{0\}|\{1\}|\|$)", "") & ")\b" ; Erase "\d[0}" and "{1}" and trailing "|". Return StringRegExpReplace($sRetPat, "\[(\d)-\1\]", "\1") ; Replace "[n-n]" with "n". EndFunc ;==>_REPatternGreaterThan Edited October 24, 2013 by Malkey Iczer 1 Link to comment Share on other sites More sharing options...
Iczer Posted October 23, 2013 Author Share Posted October 23, 2013 Nice idea, i'll use it! Thanks! 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