1

I am attempting to isolate a particular section of a line, and delete everything else after it.
Below are some example strings on what the general formatting of the file looks like. Each one of these lines I am attempting to isolate the Collection-ID.Package-name and remove the.(Version)

DGL1PLAN_PUT_PFC.FCA#FKS.(CAD17_2013-01-30-21.35.29)
DSN8CC91.DSN8CLTC.(2015-01-14-16.33.06.616783)
DSNAOCLI.DSNCLICS.(UQ40167)
DSNJAR.DSNX9DIJ.(UK81051)

Into:

DGL1PLAN_PUT_PFC.FCA#FKS
DSN8CC91.DSN8CLTC
DSNAOCLI.DSNCLICS
DSNJAR.DSNX9DIJ

I have not figured out how to delete the lines, but I have figured out (I think) how to isolate them by themselves. I am currently using ^.*(?=..(CAD)) to highlight everything before the .() on the lines. I am learning Regex and to my understanding and google searches:
^ is the beginning of the string
. finds any character except newlines
* finds 0 or more of the previous type
( begins search
?= is positive lookahead
..(CAD) is the search term I used to get it to highlight the string I want to isolate
) ends the search
I am unsure of how to delete the excess but have managed to highlight the portion I want to keep.
Here is an image of what I've figured out so far:

Attempt

6
  • 1
    Hello, please add expected output for the 4 input lines that you showed as your regex is a bit confusing.
    – Destroy666
    Commented Aug 15, 2023 at 20:49
  • @Destroy666 i dont know what output to expect. The regex I frankensteined to highlight the section I wanted to keep, I am unsure how to delete the section that isnt highlighted in the screenshot.
    – Grant Hood
    Commented Aug 15, 2023 at 20:55
  • What do you mean by "I don't know what output to expect"? That would mean this question is unanswerable. Regexes exist to change given input into given output, there's no randomness or anything. You provided 4 examplary lines and they have to be turned into some other specific lines.
    – Destroy666
    Commented Aug 15, 2023 at 20:57
  • I misunderstood what you said. For example, I am trying to take the DGL1PLAN_PUT_PFC.FCA#FKS.(CAD17_2013-01-30-21.35.29) and remove the timestamp, turning it into DGL1PLAN_PUT_PFC.FCA#FKS same with the 3 other lines.
    – Grant Hood
    Commented Aug 15, 2023 at 20:59
  • As I said, please provide it for 4 lines that you showed above. Edit the question and add it below that.
    – Destroy666
    Commented Aug 15, 2023 at 21:01

2 Answers 2

0

Use this regex:

\.\(.*

And replace with nothing (blank).

Explantation:

  • \.\( - match . and ( literally next to eachother
  • .* - match anything after those in a greedy way, to match as much as possible. Keep in mind that . matches newline option needs to be turned off, else it would match multiple lines.

This is a bit simplier than the other answer as it does the opposite - it deletes the redundant part and leaves the beginning in tact.

0
0

You can use regex: ^(.*)\.\(CAD.*\) and in replace field enter $1. This will search for string, followed by (CAD, then any symbols and ). And print only 1st group (before dot and open bracket)

If you want the same for other lines use regex: ^(.*)\.\(.*\)

Here is demonstration how it work: https://regex101.com/r/wWC24q/1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .