youtuber Posted June 24, 2019 Share Posted June 24, 2019 I want to fill the gap and merge 127.0.0.1 8080 127.0.0.1:8080 $YourIPProx = '<div class="' & @CRLF & _ 'blablablabla Your IP Proxy blabla 127.0.0.1 8080 123A123' & @CRLF & _ '</div>' $regex = StringRegExp($YourIPProx, '((?:\d{1,3}\.){3}\d{1,3})\s\d{1,4}', 3) If IsArray($regex) Then $IPProxy = StringRegExpReplace($regex[0], '((\d{1,3}\.){3}\d{1,3})\s:\d{1,5}', "$1") MsgBox(0, "", $IPProxy) EndIf Link to comment Share on other sites More sharing options...
Deye Posted June 24, 2019 Share Posted June 24, 2019 Not too hard to come up with something for this, How about: $regex = StringRegExp($YourIPProx, '(\d.*[.]\d+\s)(\d+)', 3) MsgBox(0, "", StringTrimRight($regex[0], 1) & ":" & $regex[1]) Deye youtuber 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 24, 2019 Share Posted June 24, 2019 (edited) @youtuber Try this pattern directly with with your test string (<div>...</div>) in StringRegExpReplace() function: ; Test Pattern: '(?s)(?:.*?)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s(\d+)(?:.*)' ; Replace Pattern: '$1:$2' With this pattern and replace strings, you can do what you're trying to do in one shot Edited June 24, 2019 by FrancescoDiMuro youtuber 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted June 24, 2019 Share Posted June 24, 2019 4 hours ago, youtuber said: I want to fill the gap and merge 127.0.0.1 8080 Your code was correct (one closing parenthesis to move only) $YourIPProx = '<div class="' & @CRLF & _ 'blablablabla Your IP Proxy blabla 127.0.0.1 8080 123A123' & @CRLF & _ '</div>' $regex = StringRegExp($YourIPProx, '((?:\d{1,3}\.){3}\d{1,3}\s\d{1,4})', 3) ; MsgBox(0, "", $regex[0]) If IsArray($regex) Then $IPProxy = StringReplace($regex[0], " ", ":") MsgBox(0, "", $IPProxy) EndIf youtuber 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 24, 2019 Share Posted June 24, 2019 (edited) Why don't you do something that is simpler and shorter? #include <MsgBoxConstants.au3> #include <StringConstants.au3> Global $strString = '<div class="' & @CRLF & _ 'blablablabla Your IP Proxy blabla 127.0.0.1 8080 123A123' & @CRLF & _ '</div>' MsgBox($MB_ICONINFORMATION, '', "Before: " & $strString & @CRLF & @CRLF & _ "After : " & StringRegExpReplace($strString, '(?s)(?:[^\d]*)((?:\d{1,3}\.?){4})\s(\d+)(?:.*)', '$1:$2')) Edited June 24, 2019 by FrancescoDiMuro youtuber 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted June 24, 2019 Share Posted June 24, 2019 (edited) 3 hours ago, FrancescoDiMuro said: Why don't you do something that is simpler and shorter? Because youtuber posts a lot about regex, so I assume that he wants to learn regex, and it is a way to show that his own pattern is nearly good Of course there are many ways to skin this cat Edit BTW you might test your pattern against these strings Global $strString = '<div class="' & @CRLF & _ 'blablablabla5 Your IP Proxy blabla 127.0.0.1 8080 123A123' & @CRLF & _ '</div>' Global $strString = '<div class="' & @CRLF & _ 'blablablabla Your IP Proxy blabla 5555 127.0.0.1 8080 123A123' & @CRLF & _ '</div>' Edited June 24, 2019 by mikell youtuber 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 24, 2019 Share Posted June 24, 2019 @mikell First rule of a RegEx user: "Know your string". Since there were no \d before the wanted ones, I used [^\d]; indeed, a .*? can be used to avoid such problems: #include <MsgBoxConstants.au3> #include <StringConstants.au3> Global $strString = '<div class="' & @CRLF & _ 'blablablabla5 Your IP Proxy blabla 127.0.0.1 8080 123A123' & @CRLF & _ '</div>' MsgBox($MB_ICONINFORMATION, '', "Before: " & $strString & @CRLF & @CRLF & _ "After : " & StringRegExpReplace($strString, '(?s)(?:.*?)((?:\d{1,3}\.?){4})\s(\d+)(?:.*)', '$1:$2')) youtuber 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted June 24, 2019 Share Posted June 24, 2019 Global $strString = '<div class="' & @CRLF & _ 'bla1234 5blablablabla Your IP Proxy blabla 127.0.0.1 8080 123A123' & @CRLF & _ '</div>' youtuber 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 24, 2019 Share Posted June 24, 2019 @mikell #include <MsgBoxConstants.au3> #include <StringConstants.au3> Global $strString = '<div class="' & @CRLF & _ 'bla1234 5blablablabla Your IP Proxy blabla 127.0.0.1 8080 123A123' & @CRLF & _ '<\div>' MsgBox($MB_ICONINFORMATION, '', "Before: " & $strString & @CRLF & @CRLF & _ "After : " & StringRegExpReplace($strString, '(?s)(?:.*?)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s(\d+)(?:.*)', '$1:$2')) youtuber 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
mikell Posted June 24, 2019 Share Posted June 24, 2019 Hehe it's better, and close to this one based on youtuber's pattern StringRegExpReplace($strString, '(?s).*?((?:\d{1,3}\.){3}\d{1,3})\s(\d{1,4}).*', '$1:$2') youtuber 1 Link to comment Share on other sites More sharing options...
mikell Posted June 24, 2019 Share Posted June 24, 2019 22 minutes ago, FrancescoDiMuro said: First rule of a RegEx user: "Know your string". Corollary of the First rule of a RegEx user: "be prepared to unexpected variations likely to suddenly appear in the string" FrancescoDiMuro and youtuber 2 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