Counting Characters to add non-breaking spaces

21 views
Skip to first unread message

Potts Jeff

unread,
Aug 25, 2023, 8:38:54 AM8/25/23
to TextSoap
i have a regex:

(?<=(\b(tsp|tbsp|oz|fl oz|cup|pt|qt|gal|lb|lbs|g|kg|L|mL|ds|pn|smdg|min|dr\.|lg\.|med\.|sm\.|lg|petit|sq\.|loaf|can|box|stalks|tin|square)\b))\s


I'd like to find each word in the list, count the characters and then add the appropriate number of characters to pad the line with a total of ten characters made up of the found word and a number of non breaking spaces to equal 10 characters total.


Example;


lbs       Text

kg        Text

smdg   Text


Can someone point me to an example or provide some direction


Thanks

Jeff

Mark Munz

unread,
Aug 28, 2023, 1:39:26 PM8/28/23
to text...@googlegroups.com
image.png

I generally don't like to go super specific in my matches if you can avoid it, but I am using your starting point here with specifics on measurements.
Once I have the chunk to work with (via If Text Matches)
I remove the space at the end and add 10 x's.
I then use the anchor (^) and capture 10 characters, then match the remaining text (to throw away)
Finally, I convert 'x' to non-breaking space (option-space)

You can simplify this by just using non-breaking spaces in the first Regex Find and Replace, then removing the last action,
but since spaces are (currently) difficult to see, it will make it harder to understand what is going on w/o at least a comment.


--
You received this message because you are subscribed to the Google Groups "TextSoap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to textsoap+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/textsoap/2212064a-81e2-41fe-a8bf-2266733056f1n%40googlegroups.com.


--
Mark Munz
unmarked software
https://textsoap.com/

Reply all
Reply to author
Forward
0 new messages