Jump to content
Sign in to follow this  
borism25

delete some text

Recommended Posts

borism25

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

Share this post


Link to post
Share on other sites
Melba23

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

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

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.

Share this post


Link to post
Share on other sites
borism25

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 by borism25

Share this post


Link to post
Share on other sites
PhoenixXL

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.

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  

×