0

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"

JvdV
  • 41,931
  • 5
  • 24
  • 46

2 Answers2

2

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","")
SJR
  • 22,233
  • 6
  • 16
  • 23
  • 2
    Might want to also add an `OR` for when it's followed by an underscore? – Chronocidal Jun 02 '20 at 09:13
  • @SJR nice! I added an `OR` condition and ended up with this, which works perfectly: `=IF(OR(ISNUMBER(VALUE(MID(A1,FIND("_SOL",A1)+4,1)))=TRUE,ISNUMBER(FIND("_SOL_",A1))=TRUE),"Yay","")`. Feel free to update the answer with it. I marked it as the solution as it got me to where I needed to be. – Streching my competence Jun 02 '20 at 09:31
  • Sorry, I missed that bit. Thanks for accepting - you can post your own adaptation as an answer if you wish. – SJR Jun 02 '20 at 09:46
1

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")
JvdV
  • 41,931
  • 5
  • 24
  • 46
  • 1
    Really good! I'm still just getting into reading XML formulas, so I'm going with SJR's solution for now. Upvoted though. I'm sure it is good for anyone reaching this via search! Thanks (: – Streching my competence Jun 03 '20 at 11:48
  • 1
    It's not a problem at all @Strechingmycompetence. SJR's formula is perfectly fine (you should also upvote that if it's been helpfull). Just wanted to give you the option. Have a look [here](https://stackoverflow.com/q/61837696/9758194) if these formulas interest you. – JvdV Jun 03 '20 at 11:58