.NET Regex - Find text between two characters within a single or multiple line block of text

别等时光非礼了梦想. 提交于 2020-01-06 20:19:57

问题


I have been monkeying with the following regex expression:

(\b\*)\w+(\*\b)

What I wanted to do was extract

^vitae^

from

Nam vestibulum hendrerit justo. Quisque ^vitae^ libero magna. Curabitur pretium eros ut augue ullamcorper feugiat. Aenean blandit libero vitae nunc sodales pharetra.

But what I seem to get is that regex found the text in question and returns the all of the text in the sentence as opposed to just

^vitae^

Any help would be greatly appreciated

Thanks!


回答1:


To match any text between ^

@"\^([^^]*)\^")

//matchs ^ anything that isn't ^ and finally ^

It also matches line breaks if there are any




回答2:


What about this expression:

@"\^\w+\^"


来源:https://stackoverflow.com/questions/9640051/net-regex-find-text-between-two-characters-within-a-single-or-multiple-line-b

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!