简体   繁体   中英

Regex exclude character from the group

I am trying to write this regex to match dots with a few rules

(\.+ *|([a-zA-ZÀ-ž]\.\d))(?=[^\d{1}(\.\d{1})])(?=[^.,])

But my regex is matching few characters before and after the dot as well

For example:

č.1 > match č.1 (incorrect, match should be only.)

St.M > match. (correct)

2.0 > no match (correct)

Do you have any idea, how to "exclude" these other characters from the result and match only the dot?

Thanks for your help

You could shorten the pattern using a positive lookbehind (?<=) asserting the character class with the specific ranges to the left.

(?<=[a-zA-ZÀ-ž])\.

Regex demo

As per the comments, the pattern with the positive lookahead

(?<=[a-zA-ZÀ-ž])\.+ *(?=[^.,])

Regex demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM