Need help for regular expression - find, insert and delete
-
Hello. I hope for help (absolute newbie).
I’m trying to change several linesOk I found this regex: ^\d+(-\d+)?\s
but it delete only numbers and unfortunately it’s not what I’m looking for.- Txt example - rows with numbers:
===============
02 Txt Txt Txt
220 Txt Txt Txt
03 | Txt Txt Txt | 2
130 | Txt Txt Txt | 2
etc.
================
- This is OK:
02 | Txt Txt Txt
220 | Txt Txt Txt
03 | Txt Txt Txt
130 | Txt Txt Txt
etc.
The text must be searched. Will not be a | found in the line after the number, it should be set.
Is a | at the end then delete the last digits (see example 2).Big thanks for your help!!
- Txt example - rows with numbers:
-
Perhaps this is a correct clarification:
-
If a
|character is not found after the leading digits on a line, insert it with a space before it and a space after it -
If a
|character is found anywhere else in a line, remove it and anything that follows it (and any space before it)
-
-
Thanks Alan for your Info and help.
How can I change that with regex?
From:
220 Txt Txt Txt
To:
220 | Txt Txt TxtOr delete and insert:
From:
10 Txt Txt Txt | 300
To:
10 | Txt Txt TxtSorry. I have no idea how to make regex do it…
-
I would do two separate steps:
find:
^(\d+ )([^|])
repl:${1}| ${2}and then:
find:
(?-s)^(\d+ \|.*?) \|.*
repl:${1} -
WooooooooW!
Alan -Big big thanks for your help! -
@Venus642 said in Need help for regular expression - find, insert and delete:
Big big thanks for your help!
Pay back by learning about how it worked, so that next time you don’t have to ask. :-)
Start with information HERE
-
Another option, in one step:
Search:
(?-s)(?:^(\d+) *?([A-Za-z]+))|( *?\| *?\d+)$
Replace:?1($1 | $2)Have fun!
-
One step - Perfect…
Alan and astrosofist - Top help! -
@Venus642 said in Need help for regular expression - find, insert and delete:
One step - Perfect…
Yea, I wouldn’t get too bogged down in it needing to be a one-step operation.
If it is something you need to do often, you will make it a macro anyway (so you can give it a meaningful name).
And if it is a macro, it can just as well be two replacement steps (because, by the nature of macros, multiple steps look like one step). -
@Alan-Kilborn
Alan I have tested again and your solutions is better in my case. -
@Venus642 said in Need help for regular expression - find, insert and delete:
Alan … your solutions is better
Well, I certainly wasn’t trying to “win”. :-)
I often try to point out that a solution to such a problem doesn’t have to be all crammed into one operation.
It can make the operation harder to understand for a novice with regular expressions.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login