0

I need to remove excess info in a list. Basically I want to delete everything after the first space and before the number that begins with 31117. Here is an example:

0300045956 31117016167830

0198730888 : 31117005925115

0208022376 (alk. paper) $26.00 31117005925149

0918526582;0918526590 (pbk.) 31117005925677

And what I want it to look like:

0300045956 31117016167830

0198730888 31117005925115

0208022376 31117005925149

0918526582 31117005925677

  • 0918526582;0918526590 (pbk.) 31117005925677 does not result in 0918526582 31117005925677 if the rule is "delete everything after the first space and before the number that begins with 31117". This rule would result in 0918526582;0918526590 31117005925677 – DavidPostill Feb 4 '15 at 22:09
1

The solution you asked for is to use a regular expression. You want to find:

([^ ]*)(.*)(31117*)

and replace it with:

\1 \3

This defines three groups (each is enclosed in the parentheses). The first group is zero or more non spaces; so this is everything leading up to, but not including the first space. The second group can be any number of any characters, so long as it does not start with 31117; so this is the first space and anything that follows, so long as it is not 31117. The third group is anything that starts with 31117.

Note that @DavidPostill is correct. Getting rid of everything after the first space and before the 31117 in this:

0918526582;0918526590 (pbk.) 31117005925677

is indeed:

0918526582;0918526590 31117005925677

If you misstated what you want and you really do want this:

0918526582;0918526590 (pbk.) 31117005925677

to become this:

0918526582 31117005925677

Then you need to modify the regular expression thusly:

([^; ]*)(.*)(31117*)

This adds a semicolon to the first group: any number of any characters not a space or a semicolon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.