Bugaboo
Bugaboo

Reputation: 971

Regex won't stop matching

I have the following set of strings - "Hello.There" and "HelloWorld.There"

If I do a 'Hello.*', RegEx returns both strings. How do I change my expression to return only "Hello.There"?

Upvotes: 1

Views: 86

Answers (4)

anubhava
anubhava

Reputation: 785058

You can use word boundaries in your regex:

^Hello\b.*$

With word boundaries it won't match HelloWorld

Upvotes: 3

Sabuj Hassan
Sabuj Hassan

Reputation: 39355

Your regex should be Hello\. if you want to return the string when its only contains Hello.

In regex a dot(.) means any character. You can escape this by using a escape character like this \.

Upvotes: 0

Venson
Venson

Reputation: 1870

Try this expression [Hello.]*

gskinner is a simple and good webseite to experiment with Regex

Upvotes: -1

pcnThird
pcnThird

Reputation: 2372

\bHello\.There\b

the . character is a special character in Regex. Escape it.

Upvotes: 0

Related Questions