Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
599 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Rules and regulations were devised in order to maintain the integrity of a system. However, interpretation of rules can be quite tricky.
Eseutil Hard Recovery is part of exchange tool and ensures Exchange mailbox data recovery when mailbox gets corrupt due to some problem on Exchange server.
Six Sigma Control Plans
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

876 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