Converting x//y into x/y" Excel - regex

I'm looking for a solution to convert a text stored in an Excel cell from,
x//y
into
x/y"
(preferably using serach and replace if possible)
Values of x & y will keep changing from cell to cell however pattern will be the same.
I am using Excel 2007. A VBA solution if any will be fine also.

Try =CONCATENATE(SUBSTITUTE(C2,"//","/",1),"""")
Something like above works?

No VBA Required. Try this Excel formula
=MID(A1,1,FIND("//",A1,1)-1)&"/"&MID(A1,FIND("//",A1,1)+2,LEN(A1)-FIND("//",A1,1)-1)&""""
Explanation
=MID(A1,1,FIND("//",A1,1)-1) will give you X from X//Y
=MID(A1,FIND("//",A1,1)+2,LEN(A1)-FIND("//",A1,1)-1) will give you Y

Use next pattern of RegEx for replacing //
\/\/(\w+)
with /$1"

Related

How to filter by Regex in LibreOffice?

I've got this string:
{"success":true,"lowest_price":"1,49€","volume":"1,132","median_price":"1,49€"}
Now I want the value for median_price being displayed in a cell. HHow can I achive this with Regex?
With regex101.com I've came to this solution:
(?<=median_price":")\d{0,4},\d{2}€
But this one does not seem to be working in LibreOffice calc.
I'd advise to discard the Euro-symbol at first since you'd probably want to retrieve a value to calculate with, a numeric value. Therefor try:
Formula in B1:
=--REGEX(A1;".*median_price"":""(\d+(?:,\d+)?)€.*";"$1")
The double unary will transform the result from the 1st capture group into a number. I then went ahead and formatted the cell to display currency (Ctrl+Shift+4).
Note: I went with a slightly different regular pattern. But go with whatever works for your data I supppose.

Avoid duplicate code in Excel IF formula code

I want to avoid duplicate code within excel formulas. Is there a method to repeat a certain code segment?
=IF(A1=1,(A1-B2-C3),(A1-B2-C3)+1)
This would be especially useful when it comes to more complex or longer sections. But: everything must be in ONE formula in ONE cell. Thanks! :-)
EDIT: This is my current code.
=IF(ISNUMBER(SEARCH(".amp",A2)),IFERROR(MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH(".html",A2)-FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-5),""),IFERROR(MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH(".html",A2)-FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-1),""))
It strips the long ID number out of any URL of a specific CMS. So
FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-","")))
is probably the part which occurs more than once and should be replaced for a code which does not be that duplicate-prone.
EXAMPLE: www.domain.com/path1/path2/this-is-an-article-123-dd-123456789.html --> 1234567890
EXAMPLE: www.domain.com/path1/path2/this-is-an-article-123-dd-1234567890.amp.html ->
1234567890
EXAMPLE: www.domain.com/path1/this-is-an-article-1234567890.html ->
1234567890
In google sheets, you could use REGEXEXTRACT to get what you want:
Formula in B1:
=REGEXEXTRACT(A1,"\d{8,}")
Place the complex common sub-expression in its own cell and refer to that cell.
EDIT#1:
As an alternative, you can use a Named Formula for the sub-expression:
Named Formula
So here is another way of finding the code in Excel:
Here is the formula in Cell B1 which needs to be confirmed by pressing Ctrl+Shift+Enter, then drag it down to apply across board:
{=FILTERXML("<data><a>"&SUBSTITUTE(MID(A1,LARGE(IF(MID(A1,ROW($A$1:INDEX($A:$A,LEN(A1))),1)="-",ROW($A$1:INDEX($A:$A,LEN(A1)))),1)+1,LEN(A1)),".","</a><a>")&"</a></data>","/data/a[1]")}
For the logic behind this formula you may give a read to this article: Extract Words with FILTERXML.
Cheers :)
Ps. it seems that GoogleSheet has out performed Excel in some area already.

Google sheet formula to swap names

I have this:
Image shows that those 2 cells contain input from another sheet.
Now, I want to input formula in those same cells that will rename inputs:
=if(D5="jerry.berry", "Berry Jerry", if(D5="perkins.aaron", "Aaron Perkins"))
Question: How do I insert the above formula next to =Source!H5
Note: I know I can modify those values on the root sheet itself, but I would rather not.
you can use regex like:
=ARRAYFORMULA(PROPER(REGEXREPLACE(Source!H5:H6, "(.+)\.(.+)", "$2 $1")))
I hope this is what you need:
Although I'd use a generic formula to manipulate (any) names in this string format.

Using arrayformula to add suffix, but would like to skip empty cells

I am using an arrayformula to add .png suffix to the text in column A. Right now it looks like this:
=arrayformula(A:A &".png" )
Since I want this to be a part of a macro, I won't manually be able to choose the exact range.
So how do I limit the formula, to only add the suffix, if the cells in column A had any text in it, to begin with? Right now I end up with a lot of cells where it just says ".png" because the cell was empty.
I have tried playing around with =if(istext(A:A) but I couldn't figure out how to construct the statement. And maybe it is not the way to go?
try:
=ARRAYFORMULA(INDIRECT("A1:A"&COUNTA(A:A))&".png")
or shorter:
=ARRAYFORMULA(IF(A:A="",,A:A&".png")
or regex:
=ARRAYFORMULA(REGEXREPLACE(A:A, "(.+)", "$1.png"))
See if this helps
=Arrayformula(if(len(A:A), A:A&".png",))
Using below code
=ARRAYFORMULA(A1:A&".png")
should do the thing.

Check if cell contains numbers in Google Spreadsheet using RegExMatch

I want to check if specific cell contain only numbers.
I know I should use RegExMatch but I get an error.
This is what I wrote : =if(RegExMatch(H2,[0-9]),"a","b")
I want it to say : write 'a' if H2 contains only numbers, 'b' otherwise.
Thank you
Try this:
=IF(ISNUMBER(H2,"A","B"))
or
=if(isna(REGEXEXTRACT(text(H2,"#"),"\d+")),"b","a")
One reason your match isn't working also - is that it in interpreting your numbers as text. the is number function is a bit more consistent, but if you really need to use regex, then you can see in the second formula where im making sure the that source text is matching against a string.
Your formula is right, simple you forget the double quotes at regexmatch function's regular_expression .
This is the right formula: =if(RegExMatch(B20,"[0-9]"),"a","b")
=REGEXREPLACE(“text”,”regex”,”replacement”)
It spits out the entire content but with the regular expression matched content replaced. =REGEXREPLACE(A2,[0-9],"a")
=REGEXREPLACE(A2,![0-9],"b")//not sure about not sign.
will fill a cell with the same text as A2, but with the 0-9 becoming an a!