Sign in to follow this  
Followers 0
rootx

StringRegExpReplace css tag

6 posts in this topic

I would like to replace the percentage of width

div.gallery { float: left; width:20%; }

I tried...

$colread = "10%"

$replace = StringRegExpReplace($colcss,'([0-9][^;])',$colread)

This mode does not work well, can you help me to intercept the exact text between width:????????;

Thanks guys

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Something like this ?

$colread = "10%"
$colcss = "div.gallery { float: left; width:20%; }"
$replace = StringRegExpReplace($colcss,"(?<= |;|\{)(width:)[^;]+", "${1}" & $colread)
ConsoleWrite($replace)
Edited by jguinch

Share this post


Link to post
Share on other sites

Hello,

You could try something like this:

$colcss = "div.gallery { float: left; width: 20%; }"
$colread = "10%"
$replace = StringRegExpReplace($colcss, '(?i)(width:\s?)([0-9]{1,3}%)(\s?;)', "${1}" & $colread & "${3}")

Cheers,

sahsanu

Share this post


Link to post
Share on other sites

Our examples are working. Please, post your code

Excuse me, it works perfectly, thanks

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

  • Similar Content

    • rynow
      By rynow
      Hello,
      I´m using AutoIt for a long time not only to automate applications but to develop complex stand-alone applications. I am particularly annoyed by the fact that the logic in AutoIt is difficult to separate from the presentation and the standard GUI elements are very inflexible. If you want to create something more sophisticated, you have to use GDI and write many lines for simple effects or animations.
      With these thoughts in mind, I looked around for alternatives and unfortunately found nothing that corresponded to my ideas. Therefore, I have thought of a different solution. I have created this framework in order to separate the logic from the presentation and to use HTML & CSS in my GUI to the full extent.
      Goals of the Framework
      MVC development with AutoIt HTML & CSS GUI in AutoIt Better and more modern package system(UDF) like npm CLI support like Laravel Artisan faster and more structured application development roma() is strongly inspired by Laravel PHP Framework so Laravel users will notice many similarities.
      Support
      Unfortunately, I do not have much time for the project at the moment. So I thought to myself, I share it and ask you for support.
      Content
      The framework primarily serves for the development of stand-alone applications.
      All necessary settings are preconfigured. You can start immediately with the logic or the view All settings are in one place The logic(controller) and the presentation are clearly separated from each other Development with MVC structure You can develop the GUI in realTimer without restarting AutoIt GUI can be developed in HTML & CSS Any graphic & video integration is possible (.png, .gif etc.). Also everything that is possible in HTML5 and CSS3 JavaScript & Frameworks are supported Debug logs are created including console output It is possible to work with multiple languages All UDFs are contained in the framework. Reloading is not necessary The AutoIt UDFs are also included in the Framework. This ensures that it workds correctly for different Versions of AutoIt The framework also provides functions that are necessary for communication between AutoIt and HTML. For example, evaluation of form data (GET & POST) (documentation for this and examples follow.) I also developed a template engine. (Similar to Laravel Blade) The template engine supports if statements (would like to have help to make loops possible). In the Future I will publish a complete documentation of the template engine and examples. Almost finished is a database package. This makes communication with databases an absolute child's play. So that was it for once. If something else occurs to me, I will update the list. Small Example
      url: http://localhost:8080/welcome ;application.au3 ;----------------------------------------------------------------------------------------------/ ; Initial ;----------------------------------------------------------------------------------------------/ #include 'vendor\initial.au3' func _roma_routes() ;----------------------------------------------------------------------------------------------/ ; GET Request ;----------------------------------------------------------------------------------------------/ $route_get('welcome', 'welcome') endfunc ;roma\controller\welcome.au3 ;----------------------------------------------------------------------------------------------/ ; Welcome Controller ;----------------------------------------------------------------------------------------------/ func controller_welcome() Local $name = 'Eduard', $lastname = 'Tschernjaew' ;----------------------------------------------------------------------------------------------/ ; passed variable to view (Array are possible) ;----------------------------------------------------------------------------------------------/ $toView('name', $name) $toView('lastname', $lastname) ;----------------------------------------------------------------------------------------------/ ; Return a View ;----------------------------------------------------------------------------------------------/ return $VIEW('welcome') endfunc <html> <head> <title>roma() - Template Test</title> </head> <body> <h1>Hello {{ $name }} {{ $lastname }}</h1> </body> </html>  
      Download
      The framework is under the Open-Source license.
      Github: https://github.com/4ern/roma/
      git clone https://github.com/4ern/roma.git or download the ZIP. 
      Documentaion: https://github.com/4ern/roma/blob/master/README_EN.md 
      ToDo
      [ ] Loop Funktion in Template.au3
      [ ] CLI module like Laravel Artisan
      [ ] Solution approaches, how the framework can be optimally compiled, so that in the compiled state all files are available.
      [ ] Framework Tests & Bugfixes
      roma() is still in development. Documentation and application examples will soon be available. I am looking forward to any Contributing.
      Thanks for Feedback and Contributing
    • hawkair
      By hawkair
      Hi
      I am trying to insert line numbers in to a string
      with this script
      Func _MyInc () Static Local $i = 0 $i += 1 Return $i EndFunc Exit _InsertLines() Func _InsertLines()     $String = "A" & @CRLF & "B" & @CRLF & "C" & @CRLF & "D" $NewString =  Execute("'" & StringRegExpReplace($String,"[\r\n]*",  "' & _MyInc () & '\1" ) & "'") MsgBox (0, "", $NewString) EndFunc but I get this:
      1A23B45C67D8
      I never really could master how Execute works here and I always get some working example and make substitutions.
      But this is the closest i could get...
       
    • testdriver
      By testdriver
      Greetings, all. At my wit's end trying to read element properties derived from css using IE.au3.
      The information here seems not to work for me, sadly. Anyway, my test case should be the best explanation.
       
      #include <IE.au3> Local $window_width = 640 Local $window_height = 480 $oIE = _IECreate() Local $sHTML = "" $sHTML &= "<HTML>" & @CR $sHTML &= "<TITLE>UNIQUE IDENTIFIER FOR WINDOW CLOSE</TITLE>" & @CR $sHTML &= "<HEAD>" & @CR $sHTML &= '<STYLE>.image_div {background-image: url("http://i.imgur.com/T8A46Yb.png"); width: 256px; height: 256px;}</STYLE>' & @CR $sHTML &= "</HEAD>" & @CR $sHTML &= '<body><table><tbody><tr><td id="my_div" class="image_div"></td></tr></tbody></table></body></html>' _IEDocWriteHTML($oIE, $sHTML) _IEAction($oIE, "refresh") Local $my_div = _IEGetObjById($oIE, "my_div") ;I'm trying to examine the DOM and SOMEHOW get the "http://i.imgur.com/T8A46Yb.png" address ;these seem to return empty strings ConsoleWrite(@CRLF & '$my_div.getAttribute("style") - ' & $my_div.getAttribute("style")) ConsoleWrite(@CRLF & '$my_div.getAttribute("background-image") - ' & $my_div.getAttribute("background-image")) ConsoleWrite(@CRLF & '$my_div.getAttribute("cssText") - ' & $my_div.getAttribute("cssText")) ;these return zero ConsoleWrite(@CRLF & '$my_div.style.csstext - ' & $my_div.style.csstext) ConsoleWrite(@CRLF & '$my_div.style.cssText - ' & $my_div.style.cssText) ConsoleWrite(@CRLF & '$my_div.style.CSSText - ' & $my_div.style.CSSText) ConsoleWrite(@CRLF) sleep(5000) WinClose("UNIQUE IDENTIFIER FOR WINDOW CLOSE") Basically I'm trying to get the src of a background image set through css. Any help would be much appreciated.
      Thank you for your time.
    • AutoBert
      By AutoBert
      The idea to use translation api:

      i used the script from @mikell to build this func:
      Func _Translate($sFrom, $from, $to) ;thanks to mikell (autoitscript.com) ;https://www.autoitscript.com/forum/topic/182893-prompt-me-how-to-see-the-text-in-the-translation-boxhttpstranslategooglecom/?do=findComment&comment=1313423 Local $url = "https://translate.googleapis.com/translate_a/single?client=gtx" $url &= "&sl=" & $from & "&tl=" & $to & "&dt=t&q=" & $sFrom Local $oHTTP = ObjCreate("Microsoft.XMLHTTP") $oHTTP.Open("POST", $url, False) $oHTTP.Send() Local $sData = $oHTTP.ResponseText $sData = StringRegExpReplace($sData, '.*?\["(.*?)"[^\[]*', "$1" & @CRLF) Return $sData EndFunc ;==>_Translate when i call this func with:
      $sText='AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying "runtimes" required!' MsgBox(64,'',_Translate($sText,'en','de')) nearly all is seeing here:

      only the "!" is wrong "\" but when using 'auto' instead of 'en' the result is:

      2 lines are appended. So my question is, is it possible to extend the pattern (i never worked with regex) and in best case setting @extended with the detected language?
      @Trong: as you can see yet i am returning translated text and don't use GuiCtrlSetData to assign it to a EditBox.
    • ViciousXUSMC
      By ViciousXUSMC
      I was working on something last night and decided to use StringRegExpReplace() for a config file, I never noticed that you cant just "overwrite" the file with the update so easily it required a few more pieces of code to work properly.
      Is this the simplest way (what I used) and while I searched for it and did not find it do we have or will we have a RegEx equivalent for _ReplaceStringInFile()?
      $sFile = FileRead(@ScriptDir & "\test.txt") $hFile = FileOpen(@ScriptDir & "\test.txt", 2) $sNewContent = StringRegExpReplace($sFile, "(test)", "new$1") FileWrite($hFile, $sNewContent) FileClose($hFile)