borism25 Posted February 27, 2013 Share Posted February 27, 2013 Hi! i have a litlle problem, and i don't know how to complete this, so i need a little expertise I am working in the indesign and after coping infos about pictures i get something like this: File Name | Status | page number IMG_4082.jpg OK 20 IMG_4083.jpg OK 20 IMG_4367.jpg OK 21 IMG_4090.jpg OK 20 IMG_3960.jpg OK 14 IMG_3970.jpg OK 15 IMG_3927.jpg OK 13 IMG_3981.jpg OK 15 IMG_3930.jpg OK 13 IMG_3975.jpg OK 15 IMG_3938.jpg OK 14 IMG_4072.jpg OK 20 I need to delete everything after .jpg (just need filenames) IMG_4082.jpg IMG_4083.jpg IMG_4367.jpg IMG_4090.jpg IMG_3960.jpg IMG_3970.jpg IMG_3927.jpg IMG_3981.jpg IMG_3930.jpg IMG_3975.jpg IMG_3938.jpg IMG_4072.jpg TIA Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 27, 2013 Moderators Share Posted February 27, 2013 borism25, This seems to work: $sFileText = "IMG_4082.jpg OK 20" & @CRLF & _ "IMG_4083.jpg OK 20" & @CRLF & _ "IMG_4367.jpg OK 21" & @CRLF & _ "IMG_4090.jpg OK 20" & @CRLF & _ "IMG_3960.jpg OK 14" & @CRLF & _ "IMG_3970.jpg OK 15" & @CRLF & _ "IMG_3927.jpg OK 13" & @CRLF & _ "IMG_3981.jpg OK 15" & @CRLF & _ "IMG_3930.jpg OK 13" & @CRLF & _ "IMG_3975.jpg OK 15" & @CRLF & _ "IMG_3938.jpg OK 14" & @CRLF & _ "IMG_4072.jpg OK 20" $sNewText = StringRegExpReplace($sFileText, "(?U)jpg(.*)(\v|\z)", "jpg$2") MsgBox(0, "Result", $sNewText) SRE decode: (?U) - Smallest matches jpg - Look for jpg (.*) - Capture anything up to (\v|\z) - the next EOL or EOF (which is also captured) jpg - Replace with "jpg" $2 - and the EOL/EOF we captured above All clear? 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 Link to comment Share on other sites More sharing options...
guinness Posted February 27, 2013 Share Posted February 27, 2013 Regular expression time. #include <Constants.au3> Local Const $sData = 'IMG_4082.jpg OK 20' & @CRLF & _ 'IMG_4083.jpg OK 20' & @CRLF & _ 'IMG_4367.jpg OK 21' & @CRLF & _ 'IMG_4090.jpg OK 20' & @CRLF & _ 'IMG_3960.jpg OK 14' & @CRLF & _ 'IMG_3970.jpg OK 15' & @CRLF & _ 'IMG_3927.jpg OK 13' & @CRLF & _ 'IMG_3981.jpg OK 15' & @CRLF & _ 'IMG_3930.jpg OK 13' & @CRLF & _ 'IMG_3975.jpg OK 15' & @CRLF & _ 'IMG_3938.jpg OK 14' & @CRLF & _ 'IMG_4072.jpg OK 2' & @CRLF #cs - (?m) - ^ should start at the beginning of a line. - ([^.]+\.\w+) - Capture the following to a group: - [^.]+ - Match anything that isn't a dot. - \.jpg - Match the extension .jpg and escape the dot (.). - (?:[^\r\n]+) - Don't capture the following to a group. - [^\r\n]+ - Match anything that isn't a @CR or @LF, this is greedy. #ce MsgBox($MB_SYSTEMMODAL, '', StringRegExpReplace($sData, '(?m)^([^.]+\.jpg)(?:[^\r\n]+)', '\1')) 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 Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 27, 2013 Share Posted February 27, 2013 Another example#include <Constants.au3> Local Const $sData = 'IMG.jpg_4082.jpg OK 20' & @CRLF & _ 'IMG_4083.jpg OK 20' & @CRLF & _ 'IMG_4367.jpg OK 21' & @CRLF & _ 'IMG_4090.jpg OK 20' & @CRLF & _ 'IMG_3960.jpg OK 14' & @CRLF & _ 'IMG_3970.jpg OK 15' & @CRLF & _ 'IMG_3927.jpg OK 13' & @CRLF & _ 'IMG_3981.jpg OK 15' & @CRLF & _ 'IMG_3930.jpg OK 13' & @CRLF & _ 'IMG_3975.jpg OK 15' & @CRLF & _ 'IMG_3938.jpg OK 14' & @CRLF & _ 'IMG_4072.jpg OK 2' & @CRLF #cs - (.*\.jpg) : the last literal string .jpg as capturing group 1 - .* : anything after it which is not a line-break - \1 : replace back the group one #ce ConsoleWrite( StringRegExpReplace($sData, '(.*\.jpg).*', '\1') ) My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
borism25 Posted February 27, 2013 Author Share Posted February 27, 2013 (edited) Thnx for the help I was on the work and trying to figure this out...so i paste this in excel and select (becouse of tabulator) i get 3 rows and than copy filenames Another example#include <Constants.au3> Local Const $sData = 'IMG.jpg_4082.jpg OK 20' & @CRLF & _ 'IMG_4083.jpg OK 20' & @CRLF & _ 'IMG_4367.jpg OK 21' & @CRLF & _ 'IMG_4090.jpg OK 20' & @CRLF & _ 'IMG_3960.jpg OK 14' & @CRLF & _ 'IMG_3970.jpg OK 15' & @CRLF & _ 'IMG_3927.jpg OK 13' & @CRLF & _ 'IMG_3981.jpg OK 15' & @CRLF & _ 'IMG_3930.jpg OK 13' & @CRLF & _ 'IMG_3975.jpg OK 15' & @CRLF & _ 'IMG_3938.jpg OK 14' & @CRLF & _ 'IMG_4072.jpg OK 2' & @CRLF #cs - (.*\.jpg) : the last literal string .jpg as capturing group 1 - .* : anything after it which is not a line-break - \1 : replace back the group one #ce ConsoleWrite( StringRegExpReplace($sData, '(.*\.jpg).*', '\1') ) i have about 500 filenames, does i need to put at the end & @CRLF & _ or i can do it autoamticlly for every line Edited February 27, 2013 by borism25 Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 28, 2013 Share Posted February 28, 2013 check _FileListToArray and specify the directory where the files are present then for each item use the regex pattern through a For Next loop ask for any queries you have..! Regards My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
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