Trim function within a replace
Posted: Sat Jul 09, 2011 12:50 am
The nice thing about searching first is I always find useful stuff I didn't know I needed until I found it by accident. I'd like to thank the people that take time to answer questions in this forum. I'm only learning regex but even my pitiful beginnings have made a night and day difference for me.
I manage an area in a corp where vendors do a great deal of work converting messy text and various software outputs into formats that can be machine parsed, so as you can imagine it's just a lifesaver for that stuff. I can't believe I never made more effort for this before! Now the vendors are upset because I'm saying "Hey I just did in 47 minutes, moving slowly, what it took you 3 weeks and $500-1200 to get back to me. How about you learn some decent s/r/regex so you can be competitive with cheap outside contractors I'd like to hire for 20 bucks an hour to do this instead?"
I'm just shocked at how much can be automated on the fly with this stuff once you learn even a few simple things! I think I'm really going to be able to reduce costs in my area, one of my directives from above, if I can work out stuff and share it with the people working for me. (Who really ought to learn this themselves, but cost/time means more to me than demanding that.)
It's like another language in a way, really cool.
To get to the point... I've been using a little s/r regex (posix) to grab "PTS: 1 " from any line and convert it to <value name="points">\1</points>\n (search: PTS:([^DIF]*) where DIF is text that comes after that on the line).
The problem is it captures and puts in the spaces. Now I grant I can search and replace spaces from the front and then the back of that tag, but I do this stuff on tons of tags, so what I really want is just a way to say "capture everything from here to there but when you paste it in, trim any spaces on either side of the captured content." If it helps, I can make sure the spaces are only ONE each on each side first, before doing this.
I searched in textpad and on 'trim' in this forum but I didn't find anything. Thanks for any assistance.
Best,
PJ
I manage an area in a corp where vendors do a great deal of work converting messy text and various software outputs into formats that can be machine parsed, so as you can imagine it's just a lifesaver for that stuff. I can't believe I never made more effort for this before! Now the vendors are upset because I'm saying "Hey I just did in 47 minutes, moving slowly, what it took you 3 weeks and $500-1200 to get back to me. How about you learn some decent s/r/regex so you can be competitive with cheap outside contractors I'd like to hire for 20 bucks an hour to do this instead?"
I'm just shocked at how much can be automated on the fly with this stuff once you learn even a few simple things! I think I'm really going to be able to reduce costs in my area, one of my directives from above, if I can work out stuff and share it with the people working for me. (Who really ought to learn this themselves, but cost/time means more to me than demanding that.)
It's like another language in a way, really cool.
To get to the point... I've been using a little s/r regex (posix) to grab "PTS: 1 " from any line and convert it to <value name="points">\1</points>\n (search: PTS:([^DIF]*) where DIF is text that comes after that on the line).
The problem is it captures and puts in the spaces. Now I grant I can search and replace spaces from the front and then the back of that tag, but I do this stuff on tons of tags, so what I really want is just a way to say "capture everything from here to there but when you paste it in, trim any spaces on either side of the captured content." If it helps, I can make sure the spaces are only ONE each on each side first, before doing this.
I searched in textpad and on 'trim' in this forum but I didn't find anything. Thanks for any assistance.
Best,
PJ