nafas
nafas

Reputation: 5423

\b alternatives in regular expression

Is there an alternative regular expression that matches \b.

I want something that matches . (dot) as well.

for example I want to capture ABC. (with . included)

I could write \b[\w]+\b but it doesn't capture . (dot)

I would also like to capture a word such as ABC (without dot)

So is there a way to exclude some of the characters that \b matches with?

Some of the stuff I like to match with same regular exppression:

ABC
ABC.

Upvotes: 1

Views: 1415

Answers (2)

Biffen
Biffen

Reputation: 6355

Simply specify the optional . after the \b:

\b\w+\b\.?

Upvotes: 2

npinti
npinti

Reputation: 52185

You could try something like so: (^|\s*)\w+\.($|\s*).

A working solution can be viewed here.

As per your edit, this will work: (^|\s*)([A-Za-z0-9.]+)($|\s*). Updated example here.

Upvotes: 0

Related Questions