Sign in to follow this  
Followers 0
AutID

Regex pattern get string from string

15 posts in this topic

#1 ·  Posted (edited)

Hello,

I dealing with a html source code and I have a text like this:

Dim $sString = '<a href="/track/867059" itemprop="url" class="evt-click" data-target="track">' & _
                            '<span itemprop="name">Feel So Good </span>' & _
                        '</a>' & _
                        '<span class="featuring" data-target="featuring"></span>' & _
                    '</div>' & _
                '</td>' & _
                '<td class="artist">' & _
                    '<div class="wrapper ellipsis">' & _
                        '<a class="evt-click" href="/artist/7" data-target="artist" itemprop="byArtist">Jamiroquai</a>' & _
                    '</div>' & _
                '</td>' & _
                '<td class="album">' & _
                    '<div class="wrapper ellipsis">' & _
                        '<a class="evt-click" href="/album/98952" itemprop="inAlbum" data-target="album" >A Funk Odyssey</a>' & _
                    '</div>' & _
                '</td>' & _
                '<td class="length">' & _
                    '<div class="wrapper" data-target="length"></div>' & _
                '</td>' & _
                '<td class="popularity" title="By popularity:7.85 / 10">' & _
                    '<span class="note" data-target="note"></span>' & _
                '</td>' & _
                '<td class="added">' & _
                    '<div class="wrapper ellipsis timestamp" data-target="added">' & _
                        '05:23'
                        Dim $sRet = StringRegExp($sString, 'sPattern')
                        ConsoleWrite($sRet & @LF)

and I want to get the

05:23

at the end of the line. I can do it but not with regex. How would the pattern for this look like?

Cheers

Edited by AutID

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

  1. Please don't use Dim if you can avoid it. In this case you can.
  2. Why don't you try with native string functions first? Would be good practice.
  3. If your answer to the later was you did, then great. Show us.
  4. (\d{2}:\d{2})$ << based on the content
Edited by guinness
Missing group

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

It is the laft 5 letters of the string + it has an operator between the numbers. How difficult can that be?
I came up with something like this: data-target="added">(.*?)$
However since I am actually dealing with digits, I believe your method is better.

Share this post


Link to post
Share on other sites

This ?

Local $sString = '<a href="/track/867059" itemprop="url" class="evt-click" data-target="track">' & _
                            '<span itemprop="name">Feel So Good </span>' & _
                        '</a>' & _
                        '<span class="featuring" data-target="featuring"></span>' & _
                    '</div>' & _
                '</td>' & _
                '<td class="artist">' & _
                    '<div class="wrapper ellipsis">' & _
                        '<a class="evt-click" href="/artist/7" data-target="artist" itemprop="byArtist">Jamiroquai</a>' & _
                    '</div>' & _
                '</td>' & _
                '<td class="album">' & _
                    '<div class="wrapper ellipsis">' & _
                        '<a class="evt-click" href="/album/98952" itemprop="inAlbum" data-target="album" >A Funk Odyssey</a>' & _
                    '</div>' & _
                '</td>' & _
                '<td class="length">' & _
                    '<div class="wrapper" data-target="length"></div>' & _
                '</td>' & _
                '<td class="popularity" title="By popularity:7.85 / 10">' & _
                    '<span class="note" data-target="note"></span>' & _
                '</td>' & _
                '<td class="added">' & _
                    '<div class="wrapper ellipsis timestamp" data-target="added">' & _
                        '05:23'
Local $aRet = StringRegExp($sString, '[\d:]+$', 1)
ConsoleWrite($aRet[0] & @LF)

 

Share this post


Link to post
Share on other sites

I have updated mine, as I could have sworn there was trailing space after the value. The only difference between mine and @jguinch, is mine matches two digits, colon and two digits. There's will match something like this 109:19 or :::::1982:192:::1029. So my regex is more explicit in that sense.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

Hey, by the way how can you get the "added" at 

data-target="added"

and then click it with IEAction not ConsoleWrite? please help

Share this post


Link to post
Share on other sites

If you want to use _IEAction, you have to get the DIV as an object.
With _IETagNameGetCollection, you can list all DIV objects. Next, check for each object if the data-target value is "added", then use _IEAction with the object.

Example :

Local $oDivs = _IETagNameGetCollection($oIE, "div")
For $oDiv In $oDivs
    $sDataTarget = Execute("$oDiv.attributes.getNamedItem('data-target').value")
    If $sDataTarget = "added" Then _IEAction($oDiv, "click")
Next

(note I used Execute to avoid any oject error, I don't know if this method is good or not...)


 

1 person likes this

Share this post


Link to post
Share on other sites

Ohhh GOD BLESSS you man, thanks a billion times..... you made my day .... thanks thanks thanks

much love my friend :D:lol::lmao::lol: oh godd

Share this post


Link to post
Share on other sites

Yes, thank you.. :)

one last thing if its not a bother please

what if i have some other DataTargets and i want to click them one by one, can i make it with Do...Until or Loop... or i dont know

Share this post


Link to post
Share on other sites

With my previous code, the _IEAction depends of the condition (if the data-target attribute is "added")
Either remove the condition, or make a different one.
If you want to click on each DIV having a data-target attribute, you can replace the condition by this one  :

If $sDataTarget <> "" Then _IEAction($oDiv, "click")

 


 

Share this post


Link to post
Share on other sites

Should i just replace that or put the other attributes like this: 

If $sDataTarget <> "added1, added2" Then _IEAction($oDiv, "click")

 

Share this post


Link to post
Share on other sites

No, you must use a logical operator (look at the help file in Language Reference / Operators)

Also, you can use Select or Switch  (again, in the help file in Language Reference / Conditional Statements)

If $sDataTarget = "added1" Or $sDataTarget = "added2" Then _IEAction($oDiv, "click")

 

Share this post


Link to post
Share on other sites

yes it did work perfectly, sorry for delay... and can i make it with time intervals this clicking?

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  
Followers 0