iahngy Posted February 1, 2013 Share Posted February 1, 2013 Hi there, for stringregexp , what should the pattern be for this string to search for the first plus sign ( some of spaces before + ) $str = " +---" I tried (?=\s*)[\+]*\b I remembered it works at begining but then when i turn back to try again it doesnt work anymore...Would you give me a correct pattern. Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 1, 2013 Share Posted February 1, 2013 (edited) Use the autoit tags to post script code#include <Array.au3> $str = " +---" $aRet = StringRegExp( $str, "(?<= )([+])", 3 );(?=\s*)[\+] or \s\+ _ArrayDisplay( $aRet )In your case the b is causing the problem because - is not a word boundaryrather you could use s+ as a simplified pattern Edited February 1, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
iahngy Posted February 1, 2013 Author Share Posted February 1, 2013 Thank you..it works. Link to comment Share on other sites More sharing options...
iahngy Posted February 1, 2013 Author Share Posted February 1, 2013 (edited) PhoenixXL, what if i want to search a sub string at the end of a sentence like this below...I wnt to extract 20 to get the number that i need for a calculation ...what the pattern should be? 5.0000nS 10.000nS 15.000nS 20.000nS Edited February 1, 2013 by iahngy Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 2, 2013 Share Posted February 2, 2013 (edited) Simple Stepwise approachLocal $String = "5.0000nS 10.000nS 15.000nS 20.000nS" $String = StringRegExpReplace( $String, '[^\d.\h]', '' ) ;Replace the Non-Digits exculding the periods and space $String = StringRegExpReplace( $String, '(\.\d+)', '' ) ;Replace the decimal digits MsgBox(0, 'Formatted String', $String ) ;Now two methods ;.....First Local $iString = StringRegExp( $String, '\d+$', 3 ) $iString = $iString[0] MsgBox( 64, 'Result', $iString ) ;....Second ;Get the last number MsgBox( 64, "Result", StringRegExpReplace( $String, '([.\d]+\D+)(?!$)', '' ) );Vice-versa of the First Method Direct ApproachLocal $String = "5.0000nS 10.000nS 15.000nS 20.000nS" ;Get the last number MsgBox( 64, "Result", StringRegExpReplace( $String, '.*[^.\d](\d+).+', '\1' ) );.* - match everything give back as needed ;[^.\d]- match anything that is not a digit or a period such that it is followed by ;(\d+) - [capturing group] at least one digit ;.+ - match everything left over ;\1 - Return only the digits matched Edited February 2, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
iahngy Posted February 4, 2013 Author Share Posted February 4, 2013 (edited) ;Get the last number MsgBox( 64, "Result", StringRegExpReplace( $String, '([.\d]+\D+)(?!$)', '' ) ) PhoenixXL, the code above, (?!$) .....is hard to understand and the whole thing together...does (?!$) mean look for the digit following non digit (space) of which suffix is not the end of the string ...( the end or $ is the number 20 ? )... Edited February 4, 2013 by iahngy Link to comment Share on other sites More sharing options...
iahngy Posted February 4, 2013 Author Share Posted February 4, 2013 (edited) $s = 2.73 $a = stringregexp($s, "\d\.\d\d", 4) for $i = 0 to ubound($a) - 1 $b = $a[$i] consolewrite($b[0] &$b[1] &$b[2] &$b[3] next PhoenixXL, Another problem, for ex, I have a float : 2.73 I wnt to split it into 4 parts such as 2, . , 7, 3 if I use stringregexp, what the pattern should be? mine is d.dd ...and option 4 ...it wont work . Edited February 4, 2013 by iahngy Link to comment Share on other sites More sharing options...
Xenobiologist Posted February 4, 2013 Share Posted February 4, 2013 #include #include $s = 2.73 $a = StringRegExp($s, ".", 3) ConsoleWrite(@error & @CRLF) ConsoleWrite(_ArrayToString($a, '|') & @CRLF) iahngy 1 Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
kylomas Posted February 4, 2013 Share Posted February 4, 2013 Or simply (non-regexp) #include <array.au3> $s = 2.73 $a = Stringsplit($s, '',2) _arraydisplay($a) Quote from M23, "The thing about SRE's is knowing when to use them". kylomas iahngy 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
iahngy Posted February 4, 2013 Author Share Posted February 4, 2013 (edited) Thank you both..Xeno, Interesting that just one dot it can separate into 4 parts. Kylomas, I should research more on stringsplit Edited February 4, 2013 by iahngy Link to comment Share on other sites More sharing options...
iahngy Posted February 4, 2013 Author Share Posted February 4, 2013 (edited) now i understand why just one dot...means only take 1 of whatever ..I thought i hve to use () so it remember the group Edited February 4, 2013 by iahngy Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 4, 2013 Share Posted February 4, 2013 (edited) A $ is an assertion of a EOF(?!$) - stands for anything not followed by End of FileBut i feel as per your simple aim string operations would be a much faster and easier Edited February 4, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
iahngy Posted February 11, 2013 Author Share Posted February 11, 2013 (edited) Hi, How can i make a pattern to exclude all chars except the char c or C for ex, $s = 'DX990Q_-5C_combo_whatever_uo_abc_8_1x (maybe x is here but sometimes diff char depends on the user) $pattern = '_[-5910]{1,3}[^\D86]' I just want to look for -5C or sometimes 95C or 100C or just 5 or 95 or 100 ...not 1x or 8 I put ^D to exclude all chars but how can i add something to get c or C I think i got it with this simple pattern to look for hot and cold, _-5[cC]?|_100[cC]? but if 100c or 100C is written 100t, it still take it Edited February 11, 2013 by iahngy Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 12, 2013 Share Posted February 12, 2013 (edited) Hope this helps #include <Array.au3> Local $String = "apartID124_BGA_100C_test1_testfreq_testvolt_ratio32_10x||...-200K//200op?>< 100F" Local $Match_Array = StringRegExp( $String, "(?i)-?\d+[kfc]", 3 ) _ArrayDisplay( $Match_Array ) Temperatures would most probably be in Kelvin, Fahrenheit or Celsius This regex will even support negative temperatures with the symbol Regards Edited February 12, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. 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