Regex Question
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi Regex People,
I am fairly new to regex and I am working to understand it. I am working with the expression ^.*website.+\.com.*
I am testing different strings against it to understand the expression but I cannot seem to fully grasp. Why would website.com not match that expression?
An explanation of that expression would be greatly appreciated!
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
In this case, it's a sneaky
.+
that has entered your expression. The '.' specifies any character except line breaks, whereas the '+' specifies one or more of the preceding character.
So taking your expression and turning it into English we get "starting from the beginning (^), match EVERYTHING up until the word 'website' (.*website), then match ONE OR MORE of any character (.+), then match that the string contains '.com' (\.com), ending with 0 or more of EVERYTHING"
If your aim is to make the expression match "website.com" then you could use
^.*website\.com.*$
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Adding to @lmorrell excellent explanation, if you need to match string like websiteABC.com as well as website.com, change the ".+" (one or more) to ".*" (zero or more) so your final expression becomes
^.*website.*\.com.*
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
