Jump to content
Sign in to follow this  
i2i8

How to replace parts of the same part of the keyword in the text?

Recommended Posts

i2i8

Full

<plugin
         id="com.adobe.flexbuilder.codemodel"
         download-size="0"
         install-size="0"
         version="4.5.1.313231"/>

   <plugin
         id="com.adobe.flexbuilder.crimson"
         download-size="0"
         install-size="0"
         version="4.5.1.313231"/>

   <plugin
         id="com.adobe.flexbuilder.editors.derived"
         download-size="0"
         install-size="0"
         version="4.5.1.313231"/>

   <plugin
         id="com.adobe.flexbuilder.flex"
         download-size="0"
         install-size="0"
         version="4.5.1.313231"/>

   <plugin
         id="com.adobe.flexbuilder.multisdk"
         download-size="0"
         install-size="0"
         version="4.5.1.313231"/>

   <plugin
         id="com.adobe.flexbuilder.mxmlmodel"
         download-size="0"
         install-size="0"
         version="4.5.1.313231"/>

   <plugin
         id="com.adobe.flexbuilder.project"
         download-size="0"
         install-size="0"
         version="4.5.1.313231"/>

Replacing

<plugin
         id="com.adobe.flexbuilder.project"
         download-size="0"
         install-size="0"
         version="4.5.1.313231"/>

to

<plugin
         id="com.adobe.flexbuilder.project"
         download-size="0"
         install-size="0"
         version="0.0.0"/>

Share this post


Link to post
Share on other sites
sahsanu

For me it isn't clear if you wants to replace all version fields or just project part so if you want to replace all version fields go ahead with mikell regexp (mikell is really good with regular expressions ;) ). if you just want to replace field version for project part you could use something like this:

$txt = FileRead("1.txt")
$txt = StringRegExpReplace($txt, '(?s)(.*project.*?version=")(.*?)(".*)', "${1}0.0.0${3}")
FileWrite("2.txt", $txt)

Cheers,

sahsanu

Share this post


Link to post
Share on other sites
guinness

Maybe a StringReplace() would be suffice for what they want.


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
i2i8

For me it isn't clear if you wants to replace all version fields or just project part so if you want to replace all version fields go ahead with mikell regexp (mikell is really good with regular expressions ;) ). if you just want to replace field version for project part you could use something like this:

$txt = FileRead("1.txt")
$txt = StringRegExpReplace($txt, '(?s)(.*project.*?version=")(.*?)(".*)', "${1}0.0.0${3}")
FileWrite("2.txt", $txt)

Cheers,

sahsanu

 

Very nice, you solved my problem! thank you!

Share this post


Link to post
Share on other sites
i2i8

But I don't understand what this means? 

$txt = StringRegExpReplace($txt, '(?s)(.*project.*?version=")(.*?)(".*)', "${1}0.0.0${3}") 

Share this post


Link to post
Share on other sites
Jos

But I don't understand what this means? 

$txt = StringRegExpReplace($txt, '(?s)(.*project.*?version=")(.*?)(".*)', "${1}0.0.0${3}") 

Helpfile is your friend. ;)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
sahsanu

But I don't understand what this means? 

$txt = StringRegExpReplace($txt, '(?s)(.*project.*?version=")(.*?)(".*)', "${1}0.0.0${3}") 

 

As Jos said, you could take a look to help file, in StringRegExp you have a good refrence for regular expressions.

And this is what the regular expression does:

(?s)(.*project.*?version=")(.*?)(".*)

Options: Case sensitive; Exact spacing; Dot doesn't match line breaks; ^$ match at line breaks; Greedy quantifiers; Regex syntax only

Use these options for the whole regular expression «(?s)»

   &Dot matches line breaks «s»

Match the regex below and capture its match into backreference number 1 «(.*project.*?version=")»

   Match any single character «.*»

      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»

   Match the character string “project” literally (case sensitive) «project»

   Match any single character «.*?»

      Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»

   Match the character string “version="” literally (case sensitive) «version="»

Match the regex below and capture its match into backreference number 2 «(.*?)»

   Match any single character «.*?»

      Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»

Match the regex below and capture its match into backreference number 3 «(".*)»

   Match the character “"” literally «"»

   Match any single character «.*»

      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»

${1}0.0.0${3}

Insert the text that was last matched by capturing group number 1 «${1}»

Insert the character string “0.0.0” literally «0.0.0»

Insert the text that was last matched by capturing group number 3 «${3}»

 

Cheers,

sahsanu

Share this post


Link to post
Share on other sites
i2i8

As Jos said, you could take a look to help file, in StringRegExp you have a good refrence for regular expressions.

And this is what the regular expression does:

(?s)(.*project.*?version=")(.*?)(".*)

Options: Case sensitive; Exact spacing; Dot doesn't match line breaks; ^$ match at line breaks; Greedy quantifiers; Regex syntax only

Use these options for the whole regular expression «(?s)»

   &Dot matches line breaks «s»

Match the regex below and capture its match into backreference number 1 «(.*project.*?version=")»

   Match any single character «.*»

      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»

   Match the character string “project” literally (case sensitive) «project»

   Match any single character «.*?»

      Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»

   Match the character string “version="” literally (case sensitive) «version="»

Match the regex below and capture its match into backreference number 2 «(.*?)»

   Match any single character «.*?»

      Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»

Match the regex below and capture its match into backreference number 3 «(".*)»

   Match the character “"” literally «"»

   Match any single character «.*»

      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»

${1}0.0.0${3}

Insert the text that was last matched by capturing group number 1 «${1}»

Insert the character string “0.0.0” literally «0.0.0»

Insert the text that was last matched by capturing group number 3 «${3}»

 

Cheers,

sahsanu

Thank you, thank you very much.

Share this post


Link to post
Share on other sites
mikell

sahsanu

Thanks ;)

BTW this one can be done without using backreference(s)

K can be nicely used as a kind of "lookbehind including undefinite quantifiers"

$txt = StringRegExpReplace($txt, '(?s).*project.*?version="\K([^"]+)', "0.0.0")
  • Like 1

Share this post


Link to post
Share on other sites
sahsanu

BTW this one can be done without using backreference(s)

K can be nicely used as a kind of "lookbehind including undefinite quantifiers"

$txt = StringRegExpReplace($txt, '(?s).*project.*?version="\K([^"]+)', "0.0.0")

 

That is a nice use of K. I've never used it, indeed I didn't know that it exists, so thank you, every day we learn something new ;)

Cheers,

sahsanu

Share this post


Link to post
Share on other sites
i2i8

error

Local $feature = FileRead("C:\featured.xml")
ConsoleWrite('All content:' & $feature & @CR)
Local $feature = StringRegExpReplace($feature, '(?s).*com.adobe.flexbuilder.project*?version="\K([^"]+)', "0.0.0")
ConsoleWrite('After replace:' & $feature & @CR)

The first ConsoleWrite can be output all strings, but the next step there is this kind of error:

Local $feature = StringRegExpReplace($feature, '(?s).*com.adobe.flexbuilder.project*?version="\K([^"]+)', "0.0.0")
Local $feature = StringRegExpReplace(^ ERROR

Why?

Edited by i2i8

Share this post


Link to post
Share on other sites
t1ck3ts

Another great site to help you with RegEx is http://www.regexr.com/
Its the only site thats worked my head around RegEx xD

Share this post


Link to post
Share on other sites
guinness

Another great site to help you with RegEx is http://www.regexr.com/

Its the only site thats worked my head around RegEx xD

It's a good site, though have found it to be a little buggy as of late.


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
mikell

i2i8,

- When you update $feature you must not redeclare it, else you get a "Variable used without being declared" error

- When copying the expression you forgot a dot after 'project'

Local $feature = FileRead("featured.xml")
;ConsoleWrite('All content:' & $feature & @CR)
$feature = StringRegExpReplace($feature, '(?s).*com.adobe.flexbuilder.project.*?version="\K([^"]+)', "0.0.0")
ConsoleWrite('After replace:' & $feature & @CR)

Share this post


Link to post
Share on other sites
i2i8

 

i2i8,

- When you update $feature you must not redeclare it, else you get a "Variable used without being declared" error

- When copying the expression you forgot a dot after 'project'

Local $feature = FileRead("featured.xml")
;ConsoleWrite('All content:' & $feature & @CR)
$feature = StringRegExpReplace($feature, '(?s).*com.adobe.flexbuilder.project.*?version="\K([^"]+)', "0.0.0")
ConsoleWrite('After replace:' & $feature & @CR)

AHA, I understand.Thank you very much!

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  

×