0

I have the following text.

CBEAM   241678  245002  240528  240628  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.
CBEAM   241697  245002  240230  240330  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.
CBEAM   241698  245002  240330  240430  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.
CBEAM   241699  245002  240430  240530  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.
CBEAM   241700  245002  240530  240630  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.
CBEAM   241708  245002  240231  240331  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.
CBEAM   241709  245002  240331  240431  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.
CBEAM   241710  245002  240431  240531  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.
CBEAM   241711  245002  240531  240631  10.     0.      10.     GOO
                        0.      0.2750  0.      0.      0.2750  0.

I am trying to capture both occurrences of .2750 dependent on the 2nd number of the column above it.

For example, looking at the numbers in the 2nd column,I want to change both ".2750"s for "CBEAM 241699" this would mean I'd need a search expression that grabs both .2750's that is directly below the line "CBEAM 241699".

Ideally I'd like my search expression to search and replace for multiple "CBEAM XXXXXX" which I know would consists of using "CBEAM 241710|241711", etc

My issue with my regex expression involves trying to capture data on the newline and not grabbing all the other DATA with it.

Any suggestions?

1 Answers1

-1

This regex matches what you're looking for in groups 1 and 2: (?<=CBEAM 241699|CBEAM 241711).*?(0\.2750).*?(0\.2750).

Do you want to capture several part of the text in once with a regex directly in notepad++? I think this is not possible, but I dont know notepad++. You'll have to write a script that parses your text, grabs the groups and replaces the content.

For example with python3 you can do:

infilepath = "intext.txt"
targetNumbers = ['241699', '241711']
replaceFirst = 'whatever'
replaceSecond = 'whatever2'
with open(infilepath) as text:
    text = text.read()
    for targetNumber in targetNumbers:
        text = re.sub(r'(?<=CBEAM   '+str(targetNumber)+r')(.*?)(?:0\.2750)(.*?)(?:0\.2750)(?su)', '\g<1>'+replaceFirst+'\g<2>'+replaceSecond, text)
with open('outtext.txt', 'w') as newtext:
    newtext.write(text)*

Note that the regex pattern has been modified according to this response

mquantin
  • 1,085
  • 8
  • 23
  • 1
    _`SO is not about software`_ what are you even talking about? – 1252748 Sep 20 '17 at 15:09
  • ok, you're right since notepad++ is used primarily for programming. I didn't read correctly: [Questions about ... software are off-topic for Stack Overflow unless they directly involve tools used primarily for programming.](https://stackoverflow.com/help/on-topic) I edited the answer. – mquantin Sep 20 '17 at 15:49
  • despite my clumsiness I think I fully answered the question... didn't I? – mquantin Sep 24 '17 at 12:37