twt333
twt333

Reputation: 67

How to match up until a certain character in regex

I am trying to match a wildcard url. However, I do not need to match from the start of the url path onwards.

Example: *.performance.com is all I am trying to match not *.performance.com/home

Anything from the forward slash onwards is not needed. I cant seem to state it to stop at this point this is what I have so far

/(\*\.)([\w\d]+\.)+[\w\d]+$/

Here is a regex101 link:

https://regex101.com/r/dU42kT/1

Any ideas would be greatly appreciated! Thanks.

Upvotes: 1

Views: 570

Answers (1)

The fourth bird
The fourth bird

Reputation: 163352

This part [\w\d]+can be written as \w+ as it also matches digits.

The capturing groups can be omitted if you don't need the separate values. You can omit the anchor $ at the end of the string, as a word character does not match /

You can use

\*\.(?:\w+\.)+\w+

Regex demo

Upvotes: 1

Related Questions