I have this file where I want to make a conditional check for any cell that contains the letter combination "_SOL", or where the string is followed by any numeric character like "_SOL1524", and stop looking after that. So I don't want matches for "_SOLUTION" or "_SOLothercharactersthannumeric".
So when I use the following formula, I also get results for words like "_SOLUTION":
=IF(ISNUMBER(FIND("_SOL",A1))=TRUE,"Yay","")
How can I avoid this, and only get matches if the match is "_SOL" or "_SOLnumericvalue" (one numeric character)
Clarification: The whole strings may be "Blabla_SOL_BLABLA", "Blabla_SOLUTION_BLABLA" or "Blabla_SOL1524_BLABLA"
Maybe this, which will check if the character after "_SOL" is numeric.
=IF(ISNUMBER(VALUE(MID(A1,FIND("_SOL",A1)+4,1))),"Yay","")
Or, as per OP's request and suggestion, to include the possibility of an underscore after "SOL"
=IF(OR(ISNUMBER(VALUE(MID(A1,FIND("_SOL",A1)+4,1))),ISNUMBER(FIND("_SOL_",A1))),"Yay","")
Here is an alternative way to check if your string contains SOL followed by either nothing or any numeric value up to any characters after SOL:
=IF(COUNT(FILTERXML("<t><s>"&SUBSTITUTE(A1,"_","1</s><s>")&"</s></t>","//s[substring-after(.,'SOL')*0=0]")>0),"Yey","Nay")
Just to use in an unfortunate event where you would encounter SOL1TEXT for example. Or, maybe saver (in case you have text like AEROSOL):
=IF(COUNT(FILTERXML("<t><s>"&SUBSTITUTE(A1,"_","</s><s>")&"</s></t>","//s[translate(.,'1234567890','')='SOL']")>0),"Yey","Nay")
And to prevent that you have text like 123SOL123 you could even do:
=IF(COUNT(FILTERXML("<t><s>"&SUBSTITUTE(A1,"_","1</s><s>")&"</s></t>","//s[starts-with(., 'SOL') and substring(., 4)*0=0]")>0),"Yey","Nay")
I'm fairly new to Vim and I haven't been able to find on this site how to search and replace with a varying part of a string. I need to apply a global edit to all times "SetTag("...")" appears with ... being any word. My edit is to add one more word after the second quotation mark. example: SetTag("err" + __LINE__ with the bolded part being what I need to add. Can anyone let me know how this is possible with a vim search command? Thanks!
nb: I assume "word" is any sequence of characters other than a doublequote character. Modify as needed.
:%s/SetTag("\([^"]*\)")/SetTag("\1" + __LINE__)/
the escaped parentheses grab the sub-match; the \1 in the replacement string is replaced by that sub-match.
I want to replace the 50th occurrence of Alex with Alex(the father) using vim.
The problem is this: after I execute the replace command, I want to search again for the word Alex and I do not want the replaced one to be displayed anymore.
So when I do gg49/Alex and press 'n' I want vim to skip Alex(the father) and jump to the 51st occurance of Alex (51st in the original document).
So what I want is that vim does not show me the sub-string Alex, only the exact match. Is there any way to do this?
You can do this search with a negative lookahead against a left parenthesis to avoid matching Alex when it is followed by anything that starts with (.
/\<Alex\>\((\)\#!
I need to replace a character with a pattern but the characters before the selected character also need to be replaced, using the search and replace function.
For instance: . has to be replace with 1/2, so hugo.ignatz becomes hug1/2gnatz.
How should I go about this?
If I understood you right, do you want this?
:%s#.[.].#1/2#g
this will replace x.y by 1/2
I want to replace word with WORD, but only on the lines which start with -. Anybody knows how to do it?
:%g/^-/s/word/WORD/g
it's just a normal search and replace, but using g// to filter the lines you want to run it on.