Notepad++ regex Insert string at beginning of line between two values - regex

How can I insert at the start of a line a string dependent on two other string values that define beginning and end locations?
So for example, I have
First
x
y
z
Second
a
b
c
Third
d
e
f
The result I would like to achieve is;
First
Q1 x
Q1 y
Q1 z
Second
Q2 a
Q2 b
Q2 c
Third
Q3 d
Q3 e
Q3 f
For the final section there is no string to define the end but just the end of the document.
Thanks!

This task cannot be done using pure regex(this can be proven mathematically), you would have to use something like the Notepad++ Python plugin.
This post has an example: https://superuser.com/questions/376288/how-do-i-add-input-to-my-macro-to-replace-text-in-notepad . For your task you just need to change the input parameter to the latest read cardinal number

Related

Google Sheet REGEXMATCH

can someone tell me what formula can represent the following statement :
If in Cell A1 there's value A or B or C or D then Value X must Show up in cell B1
If in Cell A1 there's value E or F or G or H then Value Y must Show up in cell B1
Thanks a ton!
I have tried REGEXMATCH function, but I wasn't able to mesh all the variables.
Try:
=IFS(REGEXMATCH(A1,"A|B|C|D"),"X",REGEXMATCH(A1,"E|F|G|H"),"Y",1,)

IF a a1 matches any cell in B:B then C

I have column D:D with names and column G:G has the same names but with numbers at the end so if D1 matches any cell in G for example G4 I need the data from H4. This is what I have so far
=IF(REGEXMATCH(D2,G2),H2,"")
I also tried
=IF(REGEXMATCH(D2:D,G2:G),H2:H,"")
[screenshot of sheet]
In K2 try
=ArrayFormula(if(len(D2:D), iferror(vlookup(regexreplace(D2:D, "(\s\(\d+\))",), G2:H, 2, 0)),))
and see if that works?

How do I get the count of non matching cells in a row between two sheets?

I have two sheets, Sheet A containing a truth table like such:
A B C D E
Foo T F F T F
Bar T F F F F
Sheet B contains another table:
A B C D E
T F F T F
I need to add a column to table A counting how many cells match the corresponding cell in sheet B, as such:
Foo T F F T F 2
Bar T F F F F 1
Best I could come up with for the first count cell was
=COUNTIF(B2:F2,B2:F2=INDIRECT("sheet-b!A2:E2"))
but this gives me 0 even though it should be 2.
Edit:
I was able to come up with this, which correctly counts the number of differing cells:
=SUM(ARRAYFORMULA(IF(B2:F2=INDIRECT("sheet-b!A2:E2"),1,0)))
The next thing I want is to add an AND statement, and count the cell if it matches or if the sheet-b cell is F:
=SUM(ARRAYFORMULA(IF(AND("F"=INDIRECT("sheet-b!A2:E2"),B5:F5=INDIRECT("sheet-b!A2:E2")),1,0)))
However it doesn't seem like i can use an AND statement in this formula. Even the following gives a sum of zero:
=SUM(ARRAYFORMULA(IF(AND(TRUE,B2:F2=INDIRECT("sheet-b!A2:E2")),1,0)))
how come?
Edit2: Link to example spreadsheet
how do I get the count of non-matching cells in a row between two sheets
=ARRAYFORMULA(IF(LEN(A2:A),
MMULT(IF(B2:F='sheet-b'!A2:E2, 0, 1), TRANSPOSE(COLUMN(B2:F2)^0)), ))
try:
=ARRAYFORMULA(IF(A1:A<>"", COUNTIFS(TRIM(
TRANSPOSE(QUERY(TRANSPOSE(Sheet2!J1:N),,999^99))),
TRANSPOSE(QUERY(TRANSPOSE(B1:F) ,,999^99))), ))

Excel | Get all column/row names in which a specific text is as a list

It is difficult for me to describe the problem in the title, so excuse any misleading description.
The easiest way to describe what I need is with an example. I have a table like:
A B C
1 x
2 x x
3 x x
Now what I want is the formula in a cell for every single column and row with each of the column or row name for every x that is placed. In the example like:
A B C
1,2 2,3 3
1 A x
2 A, B x x
3 B, C x x
The column and row names are not equivalent to the excel designation. It works with an easy WHEN statement for single cells (=WHEN(C3="x";C1)), but not for a bunch of them (=WHEN(C3:E3="x";C1:E1)). How should/can such a formula look like?
So I found the answer to my problem. Excel provides the normal CONCATENATE function. What is needed is something like a CONCATENATEIF (in German = verkettenwenn) function. By adding a module in VBA based on a thread from ransi from 2011 on the ms-office-forum.net the function verkettenwenn can be used. The code for the German module looks like:
Option Explicit
Public Function verkettenwenn(Bereich_Kriterium, Kriterium, Bereich_Verketten)
Dim mydic As Object
Dim L As Long
Set mydic = CreateObject("Scripting.Dictionary")
For L = 1 To Bereich_Kriterium.Count
If Bereich_Kriterium(L) = Kriterium Then
mydic(L) = Bereich_Verketten(L)
End If
Next
verkettenwenn = Join(mydic.items, ", ")
End Function
With that module in place one of the formula for the mentioned example looks like: =verkettenwenn(C3:E3;"x";$C$1:$K$1)
The English code for a CONCATENATEIF function should probably be:
Option Explicit
Public Function CONCATENATEIF(Criteria_Area, Criterion, Concate_Area)
Dim mydic As Object
Dim L As Long
Set mydic = CreateObject("Scripting.Dictionary")
For L = 1 To Criteria_Area.Count
If Criteria_Area(L) = Criterion Then
mydic(L) = Concate_Area(L)
End If
Next
CONCATENATEIF = Join(mydic.items, ", ")
End Function

Use a regular expression extract substring from data frame columns in R

I am fairly new to R so please go easy on me if this is a stupid question.
I have a dataframe called foo:
< head(foo)
Old.Clone.Name New.Clone.Name File
1 A Aa A_mask_MF_final_IS2_SAEE7-1_02.nrrd
2 B Bb B_mask_MF_final_IS2ViaIS2h_SADQ15-1_02.nrrd
3 C Cc C_mask_MF_final_IS2ViaIS2h_SAEC16-1_02.nrrd
4 D Dd D_mask_MF_final_IS2ViaIS2h_SAEJ6-1_02.nrrd
5 E Ee F_mask_MF_final_IS2_SAED9-1_02.nrrd
6 F Ff F_mask_MF_final_IS2ViaIS2h_SAGP3-1_02.nrrd
I want to extract codes from the File column that match the regular expression (S[A-Z]{3}[0-9]{1,2}-[0-9]_02), to give me:
SAEE7-1_02
SADQ15-1_02
SAEC16-1_02
SAEJ6-1_02
SAED9-1_02
SAGP3-1_02
I then want to use these codes to search another directory for other files that contain the same code.
I fail, however, at the first hurdle and cannot extract the codes from that column of the data frame.
I have tried:
library('stringr')
str_extract(foo[3],regex("(S[A-Z]{3}[0-9]{1,2}-[0-9]_02)", ignore_case = TRUE))
but this just returns [1] NA.
Am I simply missing something obvious? I look forward to cracking this with a bit of help from the community.
Hello if you are reading the data as a table file then foo[3] is a list and str_extract does not accept lists, only strings, then you should use lapply to extract the match of every element.
lapply(foo[3], function(x) str_extract(x, "[sS][a-zA-Z]{3}[0-9]{1,2}-[0-9]_02"))
Result:
[1] "SAEE7-1_02" "SADQ15-1_02" "SAEC16-1_02" "SAEJ6-1_02" "SAED9-1_02"
[6] "SAGP3-1_02"
str_extract(foo[3],"(?i)S[A-Z]{3}[0-9]{1,2}-[0-9]_02")
seems to work. Somehow, my R gave me
"Error in check_pattern(pattern, string) : could not find function "regex""
when using your original expression.
The following code will repeat what you asked (just copy and paste to your R console):
library(stringr)
foo = scan(what='')
Old.Clone.Name New.Clone.Name File
A Aa A_mask_MF_final_IS2_SAEE7-1_02.nrrd
B Bb B_mask_MF_final_IS2ViaIS2h_SADQ15-1_02.nrrd
C Cc C_mask_MF_final_IS2ViaIS2h_SAEC16-1_02.nrrd
D Dd D_mask_MF_final_IS2ViaIS2h_SAEJ6-1_02.nrrd
E Ee F_mask_MF_final_IS2_SAED9-1_02.nrrd
F Ff F_mask_MF_final_IS2ViaIS2h_SAGP3-1_02.nrrd
foo = matrix(foo,ncol=3,byrow=T)
colnames(foo)=foo[1,]
foo = foo[-1,]
foo
str_extract(foo[,3],regex("(S[A-Z]{3}[0-9]{1,2}-[0-9]_02)", ignore_case = T))
The reason you get NULL is hidden: R stores entries by column, hence foo[3] is the 3rd row and 1st column of foo matrix/data frame. To quote the third column, you may need to use foo[,3]. or foo<-data.frame(foo); foo[[3]].