简体   繁体   中英

how to use caret symbol in character class to match beginning of a line in Regex

Good day all .
I am trying to write regex which matches text that follows dot character or beginning of a line. so i tried this :

(?<=[^\.]).

obviously, this is not what i want. Problem is that i do not know how to specify caret symbol in character class with meaning of beginning of a line , not negation .
PS I am using .Net Regee.
Please give me some suggestions.

A character class only accepts, well, characters. Anchors like ^ are interpreted with a different meaning inside a character class.

Also, the ^ anchor matches the beginning of the line if you pass the flag RegexOptions.Multiline . If this flag isn't specified, ^ only matches the beginning of the string. If you have no access to the .NET code, you can still enable this multiline modewith the help of (?m) inline modifier that should be used at the start of the whole pattern.

However, you can use alternation to specify different options:

(?m)(?<=^|\.)

Matches when the cursor is preceded by either:

  • ^ Beginning of the line
  • \. A literal dot

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