Offir
Offir

Reputation: 3491

Vb.net regex escaping optional backslash optional in the end of a string

I have a string and i want to know if it includes some pattern in the end of it. I want to know if it has "jobs" or "jobs/" the "/" is optional for example:

www.example.jobs/ www.example.jobs

So far i have this:

 \.(com|org|edu|net|jobs?/|gov)$

The problem is that if i have a string that ends with "jobs" it doesn't catch it.

Upvotes: 0

Views: 70

Answers (2)

nu11p01n73R
nu11p01n73R

Reputation: 26667

Just add ? optional quantifier to /

\.(com|org|edu|net|jobs?/?|gov)$

Regex Demo

  • /? ensures that the / is matched zero or one time, making it optional

Upvotes: 1

garyh
garyh

Reputation: 2852

You need to escape the / so the pattern becomes

.+\.(?:com|org|edu|net|jobs|gov)\/?$

demo

Upvotes: 0

Related Questions