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
584 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 12

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 12

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 12

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

22 Experts available now in Live!

Get 1:1 Help Now