myspacee Posted October 26, 2012 Posted October 26, 2012 Hello, try to remove all ASCII code and keep numbers. Read about StringRegExp and its flag, but best result is this: $mytxt = "Where have all the flowers gone, long time p33 976 7 6761assing? E#a%t^ m(y) {sh}o=rt\s" MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($mytxt, "[a-z|A-Z|,|.]", "")) anyone can help me to obtain result = 3397676761 ? thank you, m.
Moderators Melba23 Posted October 26, 2012 Moderators Posted October 26, 2012 myspacee, Just remove all non-digits: $mytxt = "Where have all the flowers gone, long time p33 976 7 6761assing? E#a%t^ m(y) {sh}o=rts" MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($mytxt, "[^[:digit:]]", "")) M23 Andreu 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
guinness Posted October 26, 2012 Posted October 26, 2012 Local $sString = 'Where have all the flowers gone, long time p33 976 7 6761assing? E#a%t^ m(y) {sh}o=rts' MsgBox(4096, '', StringRegExpReplace($sString, '[^[:digit:]]', '')) 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
jdelaney Posted October 26, 2012 Posted October 26, 2012 (edited) $mytxt = "Where have all the flowers gone, long time p33 976 7 6761assing? E#a%t^ m(y) {sh}o=rts" MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($mytxt, "[D]", "")) returns: 3397676761 edit: too late Edited October 26, 2012 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.
Moderators Melba23 Posted October 26, 2012 Moderators Posted October 26, 2012 jdelaney,too lateBut shorter! 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
guinness Posted October 26, 2012 Posted October 26, 2012 I've been taught classes are optimised thus a little quicker, though can't prove my statement. 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
jdelaney Posted October 26, 2012 Posted October 26, 2012 Made a 14.5 meg file with the above string, and did: $mytxt = FileRead ( @DesktopDir & "regexp.txt" ) For $i = 1 To 5 Local $begin = TimerInit() $test = StringRegExpReplace($mytxt, "[D]", "") Local $dif = TimerDiff($begin) ConsoleWrite ( StringLen($test) & " time:" & $dif & @CRLF ) Local $begin = TimerInit() $test = StringRegExpReplace($mytxt, "[^[:digit:]]", "") Local $dif = TimerDiff($begin) ConsoleWrite ( StringLen($test) & " time:" & $dif & @CRLF & @CRLF ) Next output: 1753920 time:17082.5296389395 1753920 time:15682.7848564522 1753920 time:15632.913909836 1753920 time:15621.0867450618 1753920 time:15627.5870869569 1753920 time:15625.0392457119 1753920 time:15624.0357111901 1753920 time:15597.6293663864 1753920 time:15610.0859071779 1753920 time:15664.9485231092 so, yes, classes are more efficient, barely disregard the first and last, because I was doing things to affect CPU Ut won't matter on 'small' strings 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.
myspacee Posted October 26, 2012 Author Posted October 26, 2012 (edited) thank you all for help, using "[^0-9s]" option to remove all and keep only numbers. but fail in my goal. I'm trying to exctract from text files (thousand) only prices. I've some problem, because user can specify prices in different way, eg: 1.234,50 0,50 1.50 5432 etc. Want to refine "[^0-9s]" option i used, so how keep numbers and '.' and ',' ? thank you again, m. ps: thank you also for joking :] and patience Edited October 26, 2012 by myspacee
Robjong Posted October 26, 2012 Posted October 26, 2012 (edited) Hi, This should do the trick, I can not explain it right now but if you want I can explain it later. ; Match a dollar/euro sign, followed by a number, optionally followed by up to 2 dot separated segments of up to 3 digits, ; and finally optionally followed by a comma separated segment of 1 or 2 digits. $a = StringRegExp($s, "[€$]b(d+(?:.d{1,3}){0,2}(?:,d{1,2})?)b", 3) Edit: tags Edited October 26, 2012 by Robjong
masvil Posted October 11, 2016 Posted October 11, 2016 On 10/26/2012 at 6:23 PM, jdelaney said: $mytxt = "Where have all the flowers gone, long time p33 976 7 6761assing? E#a%t^ m(y) {sh}o=rts" MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($mytxt, "[D]", "")) returns: 3397676761 @jdelaney Your code doesn't work (anymore, I guess). Guinnes one does.
mikell Posted October 11, 2016 Posted October 11, 2016 Because of a typo in jdelaney's code. it should be StringRegExpReplace($mytxt, "\D", "") and FYI to negate a posix class the correct syntax is (in this case) : [[:^digit:]] czardas and masvil 2
jdelaney Posted October 13, 2016 Posted October 13, 2016 It's an old post, so it was probably good at the time, and then when converted to the newer forum, the '\' was dropped. One of my other posts also dropped the '\', but the results were as expected, which backs up my assumption. masvil 1 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.
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