Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 114
  • Last Modified:

Regex Expression in VBA

"(http://)?([\w-]+\.)([\w-]+\.)?([\w-]+)([:/].*)?"

To verify my understanding, the submatch is
1. (http://)?
2. ([\w-]+\.)
3. ([\w-]+\.)?
4. ([\w-]+)
5. ([:/].*)?

The division of "?" is following the matching expression in each portion, correct ?

For the 5th submatch : ([:/].*)?, "?" mean zero or more for the expression within (). but what does ".*" mean ? Tks


Tks
0
AXISHK
Asked:
AXISHK
  • 2
  • 2
  • 2
2 Solutions
 
ozoCommented:
The ? in (http://)? makes the match of http:// optional
The ? in ([\w-]+\.)? makes the match of [\w-]+\. optional
The ? in ([:/].*)? makes the match of [:/].* optional
0
 
Michael FowlerSolutions ConsultantCommented:
The question mark tells the regex to match 0 or 1 of the preceding pattern

so

(http://)?  allows for the pattern "http://" to be present or missing
0
 
AXISHKAuthor Commented:
Tks

([:/].*)?  -

For ".*" ,  what does it actually mean ?
.            Matches any single character except a new line character
*            Matches preceding element zero or more times
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Michael FowlerSolutions ConsultantCommented:
This matches any string which does not contain a new line. As it is zero or more times it will also match empty strings
0
 
ozoCommented:
.* matches any number of non-new line characters
0
 
AXISHKAuthor Commented:
Tks
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.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now