avechuche Posted March 13, 2014 Share Posted March 13, 2014 (edited) Hi folks, I have a problem. I need that with regular expressions, you can replace "x^x" with "x" (where x is any letter) and also need to replace "xy" with "x" (where x, y are any letter)For example: p^p = p, q^q = q, r^r=r, etc etc.qq = q I need to check that $1 and $2 are the same, in order to replace the expression for $1 or $2 (in this case is the same) $inputExpresion = StringRegExpReplace($inputExpresion, "([a-z])^([a-z])", "??????") and How do I verify that the previous character is the same as that continues and so replace the two, with one. StringRegExpReplace($inputExpresion, "([a-z])+", "?????") any solution? Thanks Edited March 13, 2014 by avechuche Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2014 Moderators Share Posted March 13, 2014 avechuche,This seems to work: $sList = "blah q^q blah" & @CRLF & _ "blah pp blah" & @CRLF & _ "blah a^b blah" & @CRLF & _ "blah cd blah" $sNewList = StringRegExpReplace($sList, "(.)(\^)?(\1)", "$1") ConsoleWrite($sNewList & @CRLF)SRER decode:(.) - Capture a character (\^)? - There might be an optional ^ (\1) - Is it the same character again? $1 - If it was, then replace the whole lot by the single characterAny use? M23 Palestinian 1 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...
avechuche Posted March 13, 2014 Author Share Posted March 13, 2014 ooooooo Nice! vey vey nice. Thanks! this is the secret, did not know (\1) - Is it the same character again? "1" refers to the first captured group, right? but (there is always a but) q^q = q its ok!!! pp = p its ok!!! a^b = a^b its ok!!! cd = cd wrong, I need only the letter "c" is maintained I'm doing a program to validate logical expressions, only that I needed to check certain things Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2014 Moderators Share Posted March 13, 2014 avechuche, "1" refers to the first captured group, right?Yes - look at the Help file for StringRegExp under "Backreferences and references to subroutines". Do I understand correctly that you want any 2-character phrase reduced to the first character? If so then this should do the trick: $sList = "blah q^q blah" & @CRLF & _ "blah pp blah" & @CRLF & _ "blah a^b blah" & @CRLF & _ "blah cd blah" $sTempList = StringRegExpReplace($sList, "(.)(\^)?(\1)", "$1") $sNewList = StringRegExpReplace($sTempList, "\s(.)(.)\s", " $1 ") ConsoleWrite($sNewList & @CRLF)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...
avechuche Posted March 15, 2014 Author Share Posted March 15, 2014 Hello, I have another problem. for example"(A | B | C) | (D | E | F)" ===> For exampleIf you find A, B or C, replace by "X" and if it is D, E or F, the Replace with "Y". It is possible by a single expression? Thx!!! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 15, 2014 Moderators Share Posted March 15, 2014 avechuche,It is trivial to do it in 2 passes:$sString = "(A | B | C) | (D | E | F)" $sNewString = StringRegExpReplace(StringRegExpReplace($sString, "[ABC]", "X"), "[DEF]", "Y") ConsoleWrite($sNewString & @CRLF)Why the requirement for a single pass? M23P.S. And was the code in post #4 what you needed? 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...
avechuche Posted March 15, 2014 Author Share Posted March 15, 2014 (edited) Oh yes, post #4 is correct. I need it in one step, because, for example:p ^ q | r =====> "|" operator is the logical "or" and "^" is the logical operator "and"In expressions, except that finds parentheses are resolved from left to right (basic math ^ ^). Thus, the first operation would have to resolve "^" (p ^ q) and then the result of that, I apply the "or". In short "p ^ q = x", then "x | r"With the example you give me the expression, solves first all "or" then all "and" and that's wrong, you have to resolve as it finds a logical operator. This is a simple example that the result is the same, but not always so. Edited March 15, 2014 by avechuche Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 16, 2014 Moderators Share Posted March 16, 2014 avechuche,Judging from that explanation you need a proper expression parser, not a simple (or even complicated) RegEx. 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 March 17, 2014 Share Posted March 17, 2014 (edited) You still can parse in one pass the expressions you have shown so far by using pattern recursion, namely (?R) or (?0) or subpattern recursion. Lookup the References to subroutines paragraph in the regexp help. If you need to deal with parenthesized sub-expressions (possibly nested) you'll have to define them as a top-level subpattern. Edited March 17, 2014 by jchd 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...
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