Regular expression

I want to check this part in a string:   -sale- or -mark-  , always four characters

12321321-sale-report
12321321-sale-csv
12321321-sale-xls
12321321-mark-report
12321321-mark-csv
12321321-mark-xls
 
byte1Asked:
Who is Participating?
 
AshokCommented:
Here is what you need.

\b(sale|mark)(?:\W+\w+){1,6}?\b

It is tested with
12321321-mark-report
or
12321321-sale-report

HTH
Ashok
0
 
CodeCruiserCommented:
You can use the string.contains method.

If str.contains("-sale-") or str.contains("-mark-")
0
 
byte1Author Commented:
i need to use that in a switch case statement.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CodeCruiserCommented:
Do you HAVE to?

May be

Select str.Contains("-sale-")
Case true
   ...
Case false
   ...
End Select
0
 
Terry WoodsIT GuruCommented:
or possibly just:
\b(sale|mark)\b
0
 
AshokCommented:
\b(sale|mark)(?:\W+\w+){1,4}?\b

Above also works!
0
 
AshokCommented:
\b(sale|mark)(?:\W+\w+)\b

Above also works!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.