Brutal 164 Posted September 20, 2017 Report Share Posted September 20, 2017 Trying to figure this out and hope for some help.lets say i have a sentence/string that has 461 characters in it... and i want to break that down into multiple 40 character strings (like if you were posting in twitter).I used regext to achieve that part with no trouble at all... Here's where i'm having trouble.Example: The following is a 40 character string...software and information that you need iThe "i" on the end of that string is actually the first letter of the next word, so what i need is to end the string on the last space (empty space) before the 40th character.This way, my string broken down into 40's (or a little less) will retain its intended structure.I'm ok with regex but no pro at it, so if there is a regex guru here, I would deeply appreciate some help. Quote Link to post Share on other sites
Marani 80 Posted September 20, 2017 Report Share Posted September 20, 2017 Try this regex: ^.{1,40}\s Quote Link to post Share on other sites
Brutal 164 Posted September 20, 2017 Author Report Share Posted September 20, 2017 thanks - that just gets the first 40 instead of each set in the string Quote Link to post Share on other sites
Marani 80 Posted September 20, 2017 Report Share Posted September 20, 2017 I'm not sure if you can do that with regex to get sets. Quote Link to post Share on other sites
Brutal 164 Posted September 20, 2017 Author Report Share Posted September 20, 2017 yeah, you can, thats how i had it set originally.... no worries, i appreciate that you tried to help man. Quote Link to post Share on other sites
Brutal 164 Posted September 21, 2017 Author Report Share Posted September 21, 2017 Solution: Not perfect, but close enough for what I needed:(?s)\G.{40,}?\b Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.