Jump to content

Help with ER


Recommended Posts

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 by avechuche
Link to comment
Share on other sites

  • Moderators

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 character
Any use? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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? :huh:

M23

P.S. And was the code in post #4 what you needed? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by avechuche
Link to comment
Share on other sites

  • Moderators

avechuche,

Judging from that explanation you need a proper expression parser, not a simple (or even complicated) RegEx. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 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 here
RegExp tutorial: enough to get started
PCRE 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...