Jump to content
Sign in to follow this  
kylomas

([SOLVED] regexp question)? - idiot ocurred 0 or 1 times

Recommended Posts

kylomas

Good Morning,

Given the following

1 12 123 9 98 987 11
*- there is a space at the beginning and end of the string

(\d{1,2})
and
(\d\d?)
return the same result. Are these stmts functionally equivalent or is this a coincidence the pattern I am using?

If they are functionally equivalent, when is one preferred over another?

Also,

The first "12" is not reported a a match. Is this because the space before it is "consumed" by the previous match?

Thanks,

kylomas

Note - I am reading through the tutorials cited by various members, including jchd, however, there are as many unanswered questions as answered questions!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Melba23

kylomas,

Disclaimer: My opinion only and I am far from expert in SREs! :D

Are these stmts functionally equivalent

Yes.

Is this because the space before it is "consumed" by the previous match?

It might be. What are you using as a pattern and what exactly are you trying to pull from this string? All the 1/2 digit numbers? All 1/2 digit combinations preceded by a space? All 1/2 digit combinations preceded and followed by a space? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Robjong

Hi,

yes these are equal.

"(d{1,2})"

d - matches any didgit
{1,2} - tells the engine to match the previous part ( d ) one or two times.

"(dd?)"

d - matches any didgit
d - matches any didgit
? - tells the engine to match the previous part ( the second d ) zero or one times.

So they both allow for one or two digits, and there are a whole lot of other ways to reach the same outcome.

Edit: You might also want to check out the example I gave here:

Edited by Robjong

Share this post


Link to post
Share on other sites
guinness

Isn't the first one more optimal?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Robjong

Not really, they should result in the same logic in the engine, but to read the expression one might prefer the former.

The matches can be one or two digits. Once the engine encounters a digit the backtrack position is stored.

The engine then goes on to see if it can match a second digit right after the first match, stores the result if it is and continues from there.

If not the engine backtracks to the last known position and saves the result and continues from there.

Edit: added explanation.

Edited by Robjong

Share this post


Link to post
Share on other sites
jdelaney

Both will return values that you probably do not expect...such as when you have 3 digits, it will be broken up into a 2digit integer and a 1digit integer.

You need to consider string begin and string ends, or include all following digits: (d+)


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Robjong

Both will return values that you probably do not expect...such as when you have 3 digits, it will be broken up into a 2digit integer and a 1digit integer.

You need to consider string begin and string ends, or include all following digits: (d+)

Excatly, but this might not be relevant to the OP. Btw. This is excatly what the example I linked to shows.

Share this post


Link to post
Share on other sites
Melba23

jdelaney,

You need to consider string begin and string ends

I quite agree with you, which is why I asked the OP what he actually expects as a return. :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jdelaney

whoops, misquoted...boundaries are key:

#include <Array.au3>
$a = StringRegExp ( "1 12 123 9 98 987 11", "b(d{1,2})b", 3 )
_ArrayDisplay ( $a )
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
kylomas

@all - Thanks for the responses.

My first question is answered.

My second question cannot be answered because I fucked up. The pattern should have read

( d{1,2} )
. The pattern, entered correctly, is returning "12" and "9". Is that because of this from Robjong

The matches can be one or two digits. Once the engine encounters a digit the backtrack position is stored.

The engine then goes on to see if it can match a second digit right after the first match, stores the result if it is and continues from there.

If not the engine backtracks to the last known position and saves the result and continues from there.

???????

Again, thanks for the prompt replies and apologies for the screw up...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
jdelaney

help us out...what EXACTLY are you expected to return from

1 12 123 9 98 987 11

put it like:

1) #

2) ##

3) etc


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
kylomas

jdelaney,

I am trying to get my arms around this cryptic language. I believe that Robjong answered this question

The first "12" is not reported a a match. Is this because the space before it is "consumed" by the previous match?

or, am I missing something again!

Apologies, again,for posting the regexp incorrectly, and, thank you for your time!

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Melba23

kylomas,

Please post what you want as a return from the RegEx as both jdelaney and I asked above - until then we cannot really answer your question! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
kylomas

M23,

Apologies if I am not being clear enough. My questions were about syntax and behavior of regexp and have been answered.

Thank you all for your time.

kylomas

P.S. If I seem to be generally confused, it is because I am! I blame too many regexp tutorials in the last 48 hours for this!


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Melba23

kylomas,

If you are happy that your questions have been answered, then fine.... :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jmosley708

I have a regexp search that works everywhere but in autoit3 it goes like this:

$sd = "Sent by Team:SYSADMIN User:jm5751"

$r = StringRegExp($sd, '([a-z]{2}d{3})(d|[a-z])',01)

ConsoleWrite('user id: ' & $r[0] & @crlf)

I can get the jm575 but I can't get the 1 after or the alpha if there is one. What can I do to fix this?

Thanks

Share this post


Link to post
Share on other sites
Malkey

If the pattern in the second capture group matches text in the test string, that text will be in the second element of the returned array.

$sd = "Sent by Team:SYSADMIN User:jm5751"
$r = StringRegExp($sd, '([a-z]{2}d{3})([da-z]?)', 1)
ConsoleWrite('user id: ' & $r[0] & $r[1] & @CRLF)

@jmosley

You should have started another thread (your own thread) instead of appending to this thread.

Share this post


Link to post
Share on other sites
jmosley708

Thanks, that worked. How do I start a new thread?

Share this post


Link to post
Share on other sites
Malkey

....

@jmosley

You should have started another thread (your own thread) instead of appending to this thread.

..... How do I start a new thread?

When you are logged on to these forums, there is a button made visible near the top of each forum that says "Start New Topic". This will allow you to weave your own topic within the fabric of that chosen forum.

Share this post


Link to post
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
Sign in to follow this  

×