Solved

Regexp and Textpad -- A way to remove all characters but 0-9 and then another to remove any not 10 in length?

Posted on 2013-02-04
5
579 Views
Last Modified: 2013-02-05
So I am typically using textpad which is a pretty good editor. I have alot of lines that need all characters but 0-9 removed (and the newline obviously per line). Is this possible?

The last thing I was wondering is if regexp can also per line, delete lines that aren't 10 in length total. I don't think this part is possible and I'll have to plug it into a database that can take some arguments (mysql) but maybe someone has an idea for that.

Thanks!
0
Comment
Question by:Valleriani
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:tel2
ID: 38852780
Something like this, perhaps Valleriani?

# Remove all non-digits
s/[^0-9]//g

# Delete lines not 10 long
s/^.({0,9}|{11,})$//
0
 
LVL 11

Expert Comment

by:tel2
ID: 38852846
Or you might have to do it this way, which works in Perl, but I don't know TextPad:
    s/[^0-9\n]//g
    s/^.{0,9}\n//
    s/^.{11,}\n//

I suggest you just try the 1st line of the above, first, see if that works, then add the 2nd line, see if that works, then add the 3rd.
Report back if you have problems, showing exactly what regex lines you're using.
0
 
LVL 7

Author Comment

by:Valleriani
ID: 38852980
Hmm, I've tried them all now but I can not get the regexp to work in Textpad. Do you perhaps have another editor that works in windows that would work with large files/your regexp?

I know something like this would work in regexp

Find What:  ^\(.\{10\}\).*
Replace With:  \1

which would find any lines greater then 10 characters and trim it. Don't know if that helps anything though.

Thanks!
0
 
LVL 11

Accepted Solution

by:
tel2 earned 500 total points
ID: 38853079
Hi Val,

No, I don't know of such regex editors for Windows, but I expect there will be some.  But is file size really a problem here?

The last regex you gave above looks as if it would just trim any chars after the 1st 10, which doesn't seem to be what you asked for.

What happens when you take my regex 1st line, and do this:
    Find What:  [^0-9\n]
    Replace With:  
Note the "Replace With" field is empty.


s/[^0-9\n]//g
0
 
LVL 7

Author Closing Comment

by:Valleriani
ID: 38854450
That does work, thank you!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A list of useful business intelligence software.
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
This video shows how use content aware, what it’s used for, and when to use it over other tools.
Viewers will learn how to use the Hootsuite Dashboard.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now