EvAsion Posted May 25, 2008 Share Posted May 25, 2008 (edited) If i have 2 capital letters next to each other, or a noncapital next to a capital, how can i put a 1 between them(or if i have a capital letter then white space or nothing, put a 1 after the capital letter)? So 'HeHP' becomes 'He1H1P1' and also, how can i put a , in a string like 'He232' between the end of the letters and the start of the numbers (becoming 'He,232'), regardless of how many letters/numbers there are on each side? something like $string = "He232" $replace = StringRegExpReplace($string, "\d?\w+","\0,") Edit: See bottom post Edited May 25, 2008 by EvAsion |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 25, 2008 Moderators Share Posted May 25, 2008 If i have 2 capital letters next to each other, or a noncapital next to a capital, how can i put a 1 between them(or if i have a capital letter then white space or nothing, put a 1 after the capital letter)? So 'HeHP' becomes 'He1H1P1' and also, how can i put a , in a string like 'He232' between the end of the letters and the start of the numbers (becoming 'He,232'), regardless of how many letters/numbers there are on each side? something like $string = "He232" $replace = StringRegExpReplace($string, "\d?\w+","\0,")oÝ÷ Ûú®¢×«b²+m«r¢æ«{ +)à¢{h«Þ¶Þ²¥iº+j×¢»ayø«²Úު笶Z(«@e©Ýk=§v·ª¹ë-jëh×6$string = "He232" $replace = StringRegExpReplace($string, "(?!:\w+)\d+",",\0") MsgBox(0, 0, $replace) 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...
EvAsion Posted May 25, 2008 Author Share Posted May 25, 2008 (edited) Thanks that works brilliantly. Well its basically for some percentage composition chemical analysis thing i am trying to implement in my periodic table. I retrieve the atomic mass of an element from a database and then multiply it by the number following. The script fails if there is no number following, so i want to make sure there is always a number between each elements, so 1 if none is specified. Something along the lines of this: $string = "HeHC" $replace = StringRegExpReplace($string, "([A-Z][a-z])[A-Z]","\0 1") msgbox(0,"",$replace) Edited May 25, 2008 by EvAsion |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
EvAsion Posted May 25, 2008 Author Share Posted May 25, 2008 Bump. |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 26, 2008 Moderators Share Posted May 26, 2008 Bump.What are you bumping? I gave you your answers.(You also may want to hold off on editing posts hour(s) after making them, some of us don't go back and read the post several times.) 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...
Sheri Posted May 26, 2008 Share Posted May 26, 2008 If i have 2 capital letters next to each other, or a noncapital next to a capital, how can i put a 1 between them(or if i have a capital letter then white space or nothing, put a 1 after the capital letter)? So 'HeHP' becomes 'He1H1P1' and also, how can i put a , in a string like 'He232' between the end of the letters and the start of the numbers (becoming 'He,232'), regardless of how many letters/numbers there are on each side? something like $string = "He232" $replace = StringRegExpReplace($string, "\d?\w+","\0,")oÝ÷ ØGbµ'nm¢jh²ßêº^N¼ëjëh×6$string = "He232" $replace = StringRegExpReplace($string, "(?i)([A-Z]+)(\d+)","$1,$2") msgbox(0,"", $string & ":" & $replace) $string = "HeHP" $replace = StringRegExpReplace($string, "(?-i)(?<=[a-zA-Z])[A-Z]|\z","@$0") $replace = StringRegExpReplace($replace, "@", "1") msgbox(0,"", $string & ":" & $replace) Hopefully your input doesn't have any @ characters, if it does you will need to choose another proxy character for the 2nd and third replacements. I couldn't find any documentation for AutoIt's regex replacement string and nothing I tried using a "1" seemed to work. Link to comment Share on other sites More sharing options...
EvAsion Posted May 26, 2008 Author Share Posted May 26, 2008 I am amazed sheri, thankyou so much. SmOke_N I very much appreciate your help aswell, I apologise for bumping. The reason i edited my post so late was because i felt that i should add an example of what I had attempted. Showing that I tried something seems to be good around here, and I did not want to sound like the type that just sais 'tell me how to do this and that', which is the general vibe of this thread already. |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| 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