EKY32 Posted January 26, 2015 Share Posted January 26, 2015 (edited) Hello, I have a text that I need to do some replacment to it's characters, lets say I need to replace the dashes "-" with spaces, but I do not want the dashes inside the anchor tag to be replaced, only the ones outside it. $text = "here is the link http://www.my-li-nk.com that should stay as is, and here are-the-dashes-that-need-to-be replaced with spaces" I've previously used >somoke_n's code to identify the anchor tag. Func _replaceURLWithHTMLLinks($sText) Local Const $sExp = "(?i)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])" Return StringRegExpReplace($sText, $sExp, "<a href='$1'>$1</a>") EndFunc Thanks in advance. Edited January 26, 2015 by EKY32 [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
Valuater Posted January 26, 2015 Share Posted January 26, 2015 $split = stringsplit( $string, ".com") Stringreplace($split[0], "-", " ") for $x = 1 to $split[0] -1 $newstring &= $spli[$x] next msgbox(0,0,$newstring) --------------------------------------------- written on screen... not testd... but you gat the idea 8) EKY32 1 Link to comment Share on other sites More sharing options...
EKY32 Posted January 26, 2015 Author Share Posted January 26, 2015 (edited) Thanks, I don't think this helps in my situation, In fact, I do not know the real URL, I'm filtering a long amount of text, converting the plain text URLs to real HTML coded ones, and then replace some other characters (like smiles for example..) with image codes .. so I do not want the smile filtering function to approach to the URLs and replace any of their text. Thanks. Edited January 26, 2015 by EKY32 [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 26, 2015 Moderators Share Posted January 26, 2015 1. get an array of urls with regex 2. replace urls with unique strings that also represent the index of the url in your array 3. replace all the characters you need to 4. replace the unique strings with the array of urls based on index EKY32 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 26, 2015 Moderators Share Posted January 26, 2015 EKY32.How about this: $sFiller = "###" $sText = "here is the link http://www.my-li-nk.com that should stay as is, and here are-the-dashes-that-need-to-be replaced with spaces" ; Extract the link $sExtract = StringRegExpReplace($sText, "^.*(http\S*)\s.*$", "$1") ; Replace the link by the filler, get rid of the dashes and then replace the link $sNewText = StringReplace(StringReplace(StringReplace($sText, $sExtract, $sFiller), "-", " "), $sFiller, $sExtract) ConsoleWrite($sNewText & @CRLF)M23 EKY32 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 Link to comment Share on other sites More sharing options...
Solution jguinch Posted January 26, 2015 Solution Share Posted January 26, 2015 SmOke_N's way can be something like this : #Include <Array.au3> ; just for _ArrayDisplay $text = "here is the link http://www.my-li-nk.com that should stay as is, and here are-the-dashes-that-need-to-be replaced with spaces." ; Extract all links $aLinks = StringRegExp($text, "(?i)(\b(?:https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])", 3) _ArrayDisplay($aLinks, "All links") ; Replace all links by a mark : <link{x}> For $i = 0 To UBound($aLinks) - 1 $text = StringReplace($text, $aLinks[$i], "<link{" & $i & "}>", 1) Next ConsoleWrite($text & @CRLF) ; replace all dashes between two words by a blank $text = StringRegExpReplace($text, "(?<=\w)-(\w+)", " $1") ConsoleWrite($text & @CRLF) ; Replace each mark by its variable name $text = StringReplace($text, '"', '""') $text = StringRegExpReplace('"' & $text & '"', "<link\{(\d+)\}>", '" & \$aLinks[$1] & "') ConsoleWrite($text & @CRLF) ; Replace each variable by its value $text = Execute($text) ConsoleWrite($text & @CRLF) EKY32 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
EKY32 Posted January 26, 2015 Author Share Posted January 26, 2015 You people are all geniuses, i'm very thankful to all of you. All the methods worked fine but the one jguinch posted was perfect to my need. Thank you all again. [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
Malkey Posted January 26, 2015 Share Posted January 26, 2015 And another one. Local $sText = "here is the link http://www.my-li-nk.com and another http://www.his-li-nk.com that should stay as is, and here are-the-dashes-that-need-to-be replaced with spaces" Local $sStr = '"' & StringRegExpReplace($sText, "([\w.,/:]+(?:\-[\w.,/:-]+))", '" & (StringRegExp("${1}","^http") ? "${1}" : (StringRegExpReplace("${1}","-"," "))) & "') & '"' ;ConsoleWrite($sStr & @LF) ConsoleWrite(Execute($sStr) & @LF) jguinch and EKY32 2 Link to comment Share on other sites More sharing options...
jguinch Posted January 26, 2015 Share Posted January 26, 2015 Nice use of the ternary operator in an Execute sequence... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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