lordsocke Posted April 19, 2018 Posted April 19, 2018 Hey there, my code: Global $res = StringRegExp($text,"\n", 3) If @error Then $nbOccurencesn = 0 Else $nbOccurencesn = UBound($res) Endif ConsoleWrite(@crlf&$nbOccurencesn&@crlf) is not delivering any hits in the string: "Which Reese Witherspoon movie\nhas gotten a Broadway musical\nadaptation?\nElection\nWalk the Line\nLegally Blonde\n" any Ideas what im making wrong?
iamtheky Posted April 19, 2018 Posted April 19, 2018 (edited) looking for a literal, and not escaping the character also used for pattern matching $text = "Which Reese Witherspoon movie\nhas gotten a Broadway musical\nadaptation?\nElection\nWalk the Line\nLegally Blonde\n" Global $res = StringRegExp($text,"\\n", 3) If @error Then $nbOccurencesn = 0 Else $nbOccurencesn = UBound($res) Endif ConsoleWrite(@crlf&$nbOccurencesn&@crlf) from helpfile: Quote \n Represents "linefeed" (@LF, Chr(10)). so thats what you were looking for and why a one line string would correctly return 0 Edited April 19, 2018 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted April 20, 2018 Posted April 20, 2018 Anyway the real purpose is hopefully different, because such a simple thing doesn't need a regex $text = "Which Reese Witherspoon movie\nhas gotten a Broadway musical\nadaptation?\nElection\nWalk the Line\nLegally Blonde\n" $res = StringReplace($text,"\n", "\n") ;Global $res = StringRegExp($text,"\n", 3) If not @extended Then ;@error Then $nbOccurencesn = 0 Else $nbOccurencesn = @extended ;UBound($res) Endif ConsoleWrite(@crlf&$nbOccurencesn&@crlf)
lordsocke Posted April 22, 2018 Author Posted April 22, 2018 On 20.4.2018 at 9:28 PM, mikell said: Anyway the real purpose is hopefully different, because such a simple thing doesn't need a regex $text = "Which Reese Witherspoon movie\nhas gotten a Broadway musical\nadaptation?\nElection\nWalk the Line\nLegally Blonde\n" $res = StringReplace($text,"\n", "\n") ;Global $res = StringRegExp($text,"\n", 3) If not @extended Then ;@error Then $nbOccurencesn = 0 Else $nbOccurencesn = @extended ;UBound($res) Endif ConsoleWrite(@crlf&$nbOccurencesn&@crlf) But the Thing is, that I need to keep the \n inside the code.
lordsocke Posted April 22, 2018 Author Posted April 22, 2018 On 20.4.2018 at 9:28 PM, mikell said: Anyway the real purpose is hopefully different, because such a simple thing doesn't need a regex $text = "Which Reese Witherspoon movie\nhas gotten a Broadway musical\nadaptation?\nElection\nWalk the Line\nLegally Blonde\n" $res = StringReplace($text,"\n", "\n") ;Global $res = StringRegExp($text,"\n", 3) If not @extended Then ;@error Then $nbOccurencesn = 0 Else $nbOccurencesn = @extended ;UBound($res) Endif ConsoleWrite(@crlf&$nbOccurencesn&@crlf) thanks!
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