Deleting all numbers with specific letter(s)
-
Hello. I have lines like these:
9.15 Premjera. Senis.395 s.
10.20 Premjera. Štutgarto kriminalinė policija.8/12 s.
I want to delete every “395 s.” and “8/12 s.” without disturbing other numbers. Also these numbers keeps changing like (395 s., 396 s., 397 s. and 8/12 s., 8/13 s.
Is it possible? -
Why does it seem like every problem is a regex problem today?
Try this:
Find what zone:
\.(?:(?:[0-9/]+)|(?:\d+))\x20s\.
Replace with zone: leave this empty
Wrap around checkbox: as desired
Search mode: Regular expression
Action: Press Replace / Replace All buttonHere’s an explanation of how it works:
- [Match the character “.” literally][1 ]
\.
- [Match the regular expression below][2 ]
(?:(?:[0-9/]+)|(?:\d+))
- [Match this alternative (attempting the next alternative only if this one fails)][3 ]
(?:[0-9/]+)
- [Match the regular expression below][2 ]
(?:[0-9/]+)
- [Match a single character present in the list below][4 ]
[0-9/]+
- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ]
+
- [A character in the range between “0” and “9”][4 ]
0-9
- [The literal character “/”][6 ]
/
- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ]
- [Match a single character present in the list below][4 ]
- [Match the regular expression below][2 ]
- [Or match this alternative (the entire group fails if this one fails to match)][3 ]
(?:\d+)
- [Match the regular expression below][2 ]
(?:\d+)
- [Match a single character that is a “digit” (any symbol with a decimal value in the active code page)][7 ]
\d+
- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ]
+
- [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ]
- [Match a single character that is a “digit” (any symbol with a decimal value in the active code page)][7 ]
- [Match the regular expression below][2 ]
- [Match this alternative (attempting the next alternative only if this one fails)][3 ]
- [Match the character “ ” which occupies position 0x20 (32 decimal) in the character set][8 ]
\x20
- [Match the character “s” literally (case sensitive)][6 ]
s
- [Match the character “.” literally][1 ]
\.
Created with RegexBuddy
[1 ]: http://www.regular-expressions.info/characters.html#special
[2 ]: http://www.regular-expressions.info/brackets.html
[3 ]: http://www.regular-expressions.info/alternation.html
[4 ]: http://www.regular-expressions.info/charclass.html
[5 ]: http://www.regular-expressions.info/repeat.html
[6 ]: http://www.regular-expressions.info/characters.html
[7 ]: http://www.regular-expressions.info/shorthand.html
[8 ]: http://www.regular-expressions.info/nonprint.html - [Match the character “.” literally][1 ]
-
Hello, @berniukas-neziniukas, @scott-sumner and All,
Scott, am I missing something obvious ?!
As, from the sentence :
I want to delete every “395 s.” and “8/12 s.” without disturbing other numbers.
It seems, to my mind, that the correct search regex is, simply, the obvious one, below :
\.(395|8/12)\x20s\.
Cheers,
guy038
-
@guy038 it appears you did miss the obvious. That being the next sentence:
@Berniukas-Neziniukas said:
Also these numbers keeps changing like (395 s., 396 s., 397 s. and 8/12 s., 8/13 s.
So the numbers aren’t always the same, hence your regex will miss other “similar” but different numbers.
Terry
-
Hi, @terry-r,
Ah, I see ! Actually, the OP meant :
I want to delete every expression “395 s.” and “8/12 s.” and similar ones, without disturbing other numbers, in other forms !
I didn’t notice the difference :-((
Best Regards,
guy038
-
@guy038, yes we seem to often find posters whose primary language is NOT English, doing a fine job of writing in English, but those subtle nuances are what impart a lot more information.
I’m actually going through the old posts (a little project of mine, we will see if it works out) and invariably the writing styles of the OPer is what causes most of the issues initially. Just getting the understanding right before launching into a regex is key to a good solution.
Just an observation
Terry
-
@Scott-Sumner This did the trick. You saved me a lot of time, thank you very much!
-
@guy038 Sorry for being unclear! Sometimes I read my older posts and wonder how people managed to find any sense in them. That’s why I post so rarely…