Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript regex question (.*)

I am using VBscript in QTP and I am a bit confused:

Browser("name:=.*") //works

Why Browser("name:=*") does not work? Why is there a . character?

Thank you!

like image 649
Thomas Avatar asked Jul 23 '26 04:07

Thomas


2 Answers

While normal wildcards (such as those used in shells for specifying many files at once—e. g. *.txt) use only the askterisk (*) as a sign for at zero or more arbitrary characters, in regular expressions it is a quantifier. It tells the regex engine something about the preceding token. A dot (.) matches a single arbitrary character, a dot followed by an asterisk thereby matches zero or more arbitrary characters.

However, a = followed by a * will match 0 or more equals signs (=)—since the asterisk always works on the preceding token, which is just the equals sign here.

Note: A token can be many things, a single character like the =, a character class, such as ., \w or [a-z], a group such as (abc) which would then match any string like abcabcabc, &c. This allows for much richer types of expressions you can define than just the plain old wildcards.

Generally the following equivalences between wildcards and regular expressions hold—approximately; there are some details which may not immediately be obvious:

Wildcard        Regex
--------        -----
*               .*
?               .
[a-z]           [a-z]
like image 173
Joey Avatar answered Jul 27 '26 14:07

Joey


The * means: match an expression where the character to the left from the * appears 0 or more times. . means 'match any character'. So .* means: match any character 0 or more times. In your second expression, there is an equal sign before the *, so it means: match 0 or more equal signs.

like image 28
Doc Brown Avatar answered Jul 27 '26 13:07

Doc Brown



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!