Jump to content

Regexp: how to match NOT ellips


leuce
 Share

Recommended Posts

G'day everyone

What would the regular expression be to NOT match "...". In other words, I want the match result to be "positive" if three consecutive dots (periods, fullstops) were not found.

In other words, if I have this script:

$question = "Soek tans."
; $rule = ???
If StringRegExp ($question, $rule, 0) = 1 Then
MsgBox (0, "", "Yes", 0)
EndIf

...and I wish to get a "Yes" message if "..." is not in the $question, what should the $rule be?

Ideally I would like to exclude the three dots as a single group, but if that is not possible, being able to exclude them as three separate dots would be fine as well.

Thanks

Samuel

Link to comment
Share on other sites

  • Moderators

leuce,

Just use Not to reverse the match: ;)

Global $aString[2] = ["abcde...abcde", "abcde---abcde"]

For $i = 0 To 1

    If Not StringRegExp($aString[$i], "(.){3}") Then
        ConsoleWrite("Element " & $i & " - '...' not found" & @CRLF)
    EndIf

Next

Now you only action if the "..." is NOT found. :)

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

[^.]{3,3}

Just use Not to reverse the match...

I don't want to use "Not" to reverse the match because then the user would have to maintain two sets of regular expressions -- one that matches If Not statements and that that matches If statements. I want to give the user the ability to specify a regular expession, which is then executed by the script.

Can AutoIt's regex do this? I tried all kinds of options that seemed logical to me... but to no avail. Maybe I should just tell the user "sorry, you can't check for the absence of three dots". :(

Samuel

Link to comment
Share on other sites

  • Moderators

leuce,

How about explaining further what it is you want to do with all this. Giving us only a part formulated question is, as we have just proved, very unlikely to get you the answer you want. ;)

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

How about explaining further what it is you want to do with all this.

I have a script that checks lines a large text file for the presence of strings. The user specifies these strings in a separate file (say, a strings file). If a string is present in a line in the text file, the script outputs a report that informs the user about it. The purpose of this is to help check for errors or portential errors in the written text. If a certain word or phrase does or does not occur in the writtten text, it may be an error, and the user wants to be warned about it.

Apart from simple strings, it would be great if the user could also specify regular expressions, because regular expressions would allow the user to specify more natural language.

For example, if a line of text contains "the quick brown fox" and the strings file contains the rule "the brown fox", and I would like the rule to match the line, then only a regular expression would do that.

In the case of the three dots, the issue is that if "tans" is present but three dots are not, then the report should contain an entry. So if the line of text is "Stuur tans.", then the report should contain an entry because the word "tans" is present but the three dots is absent.

Another hypothetical example may be that if the line of text contains "diningroom", "laundryroom", "familyroom" but not "bedroom", then there should be a report about it. In such a case, the user would specify something like ^(bed)room or perhaps (bed){0,0}(room), which I had thought would match "diningroom" but not "bedroom"... but that's not the right syntax, and I have no idea what the correct syntax would be. I can't seem to figure out how the "not" in regular expressions work.

Here's another example that I'm breaking my head over: The sentence "geen doel nie." should not trigger a report but the sentence "geen doel." should. I had thought that I could specify bgeenb.*^(nie) or perhaps something like bgeenb.*(nie){0,0} to do this, but these regular expressions do not have the desired effect.

Samuel

Edited by leuce
Link to comment
Share on other sites

  • Moderators

leuce,

I will have a think about the "..." case, but I can help immediately with the "room" search: ;)

Global $aRooms[4] = ["diningroom", "laundryroom", "familyroom", "bedroom"]

For $i = 0 To 3
    If StringRegExp($aRooms[$i], "(?i)(?<!bed)room") Then
        ConsoleWrite($i & " does NOT contain 'bedroom'" & @CRLF)
    EndIf
Next

The structure is called a "negative lookbehind" and is only true if "room" is not immediately preceded by "bed". :)

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

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...