find a string in a sentence using regex

enthuguy
enthuguy used Ask the Experts™
on
Hi,
Would like to find a string in a sentence using regex
Basically I have two variables similar to below and valuate true or false
VAR1=”NY,CO,NJ,FL”
VAR2=”NY”

Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
What is the string you want to find, what is the sentence you want to find in, and what shell are you using to do it?

Author

Commented:
Sorry

Find var1 in var2
Most Valuable Expert 2014
Top Expert 2015
Commented:
#!/usr/bash
VAR1="NY,CO,NJ,FL"
VAR2="NY"
[ "${VAR1/$VAR2/}" != $VAR1 ] && echo found $VAR2 in $VAR1

Open in new window

OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Author

Commented:
Sorry other way around

Find var2 in var1

Author

Commented:
Thx ozo,  is this using regular expression?
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
It uses pathname expansion.  
Regular expressions did not seem to be needed to accomplish what you seemed to be asking for in this case.
Is there another example that needs regular expressions?

Author

Commented:
I think i can use this as well
Thanks ozo

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial