HurleyShanabarger Posted September 6, 2017 Share Posted September 6, 2017 Hi guys, is there an easy pattern to remove the a specific leading/trailing char from a line? In my case it is the quotation mark, that might be in the first/and or last place and as well in the middle of each line. "test_line_1 test_line_2" "test_line_3" test"l"in"e_4" I would like to have this as output: test_line_1 test_line_2 test_line_3 test"l"in"e_4 That is the pattern that I have but iut won't match the last one: StringRegExp($_lv_sString, "(?m)^["]?(.*)", 3) Thanks! Link to comment Share on other sites More sharing options...
Danyfirex Posted September 6, 2017 Share Posted September 6, 2017 Hello. Maybe something like this. Local $sString = '"test_line_1' & @CRLF & _ 'test_line_2"' & @CRLF & _ '"test_line_3"' & @CRLF & _ 'test"l"in"e_4"' & @CRLF $sString = StringRegExpReplace($sString, '(?m)^"|"$', "") ConsoleWrite($sString & @CRLF) Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
mikell Posted September 6, 2017 Share Posted September 6, 2017 Could also be like this, depending on the exactly expected result ... StringRegExpReplace($sString, '(?m)^"|"(?=[^"]*"$)|"$', "") Link to comment Share on other sites More sharing options...
Simpel Posted September 6, 2017 Share Posted September 6, 2017 Hi. Because you wanted StringRegExp: #include <Array.au3> Local $_lv_sString = '"test_line_1' & @CRLF & _ 'test_line_2"' & @CRLF & _ '"test_line_3"' & @CRLF & _ 'test"l"in"e_4"' & @CRLF Local $aArray = StringRegExp($_lv_sString, '(?m)^"*(.*\d+)', 3) _ArrayDisplay($aArray) Conrad SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
Simpel Posted September 6, 2017 Share Posted September 6, 2017 Because my post above was only some kind of work around and not exactly what you asked for (it only worked for you example but not in general) I tried a bit and here's a solution for general purpose: #include <Array.au3> Local $_lv_sString = '"test_line_1' & @CRLF & _ 'test_line_2"' & @CRLF & _ '"test_line_3"' & @CRLF & _ 'test"l"in"e_4"' & @CRLF Local $sSpecificLeadingTrailingChar = '"' Local $sRegex = '(?m)^\' & $sSpecificLeadingTrailingChar & '?(.+?)(?:\' & $sSpecificLeadingTrailingChar & '*$)' Local $aArray = StringRegExp($_lv_sString, $sRegex, 3) _ArrayDisplay($aArray) Conrad SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
HurleyShanabarger Posted September 8, 2017 Author Share Posted September 8, 2017 Thanks you guys, the solution von mikell is working the best for me. NDog 1 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